You can escape my_name
using double curly brackets, like this
>>> my_string = 'Hello {name}, my name is {{my_name}}!'
>>> my_string.format(name='minerz029')
'Hello minerz029, my name is {my_name}!'
As you can see, after formatting once, the outer {}
is removed and {{my_name}}
becomes {my_name}
. If you later want to format my_name
, you can simply format it again, like this
>>> my_string = 'Hello {name}, my name is {{my_name}}!'
>>> my_string = my_string.format(name='minerz029')
>>> my_string
'Hello minerz029, my name is {my_name}!'
>>> my_string.format(my_name='minerz029')
'Hello minerz029, my name is minerz029!'
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…