1

I would like to know how could I format this string:

"){e<=2}"

This string is inside a function, so I would like to asign the number to a function parameter to change it whenever I want.

I tried:

"){e<={0}}".format(number)

But it is not working, Could anybody give me some advice? Thanks in advance

1
  • 1
    {{ and }} would not be considered as placeholders by format: stackoverflow.com/questions/5466451/…, so you can write "){{e<={0}}}" instead of "{e<={0}}" Commented Mar 3, 2020 at 10:45

2 Answers 2

1

Double the braces which do not correspond to the format placeholder...

"){{e<={0}}}".format(number)

You could also use an f-string, if using Python 3.6 or above.

f"){{e<={number}}}"
Sign up to request clarification or add additional context in comments.

Comments

0

An old-school version for this:

"){e<=%d}" % (number)
'){e<=2}'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.