The string already has '{'
inside it. Now I want to use python format method.
a = "{foo{}}"
b = a.format("bar")
result should be {foobar}
There are many ways to solve the problem but I want to know is there a way to skip first '{'
.
The string already has '{'
inside it. Now I want to use python format method.
a = "{foo{}}"
b = a.format("bar")
result should be {foobar}
There are many ways to solve the problem but I want to know is there a way to skip first '{'
.
To have a regular brace, use it twice in a format string.
>>> "{{foo{}}}".format("bar")
'{foobar}'
You could use the %x syntax as well:
a = "{foo%s}"
b = a % 'bar'
Which will return '{foobar}'
just fine.
FYI: to print % in a string you would use %%
.