Ponder that you have a string which looks like the following 'This string is {{}}'
and you would like to transform it into the following 'This string is {wonderful}'
if you do 'This string is {{}}'.format('wonderful')
it won't work. What's the best way to achieve this?
You just need one more pair of {}
'This string is {{{}}}'.format('wonderful')
you need triple brackets: two for the literal {
and }
and the pair in the middle for the format function.
print('This string is {{{}}}'.format('wonderful'))
Two brackets to get {}
in line (escaping), and third as placeholder:
'This string is {{{}}}'.format('wonderful')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With