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

EdChum
  • 376,765
  • 198
  • 813
  • 562
Jeni
  • 918
  • 7
  • 19
  • 1
    `{{` and `}}` would not be considered as placeholders by `format`: https://stackoverflow.com/questions/5466451/how-can-i-print-literal-curly-brace-characters-in-python-string-and-also-use-fo, so you can write `"){{e<={0}}}"` instead of `"{e<={0}}"` – ionagamed Mar 03 '20 at 10:45

2 Answers2

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}}}"
wstk
  • 1,040
  • 8
  • 14
0

An old-school version for this:

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