我在使用f-string
时遇到了以下问题:
>>> a='hello'
# how to print '{hello}' ?
>>> f'{{a}}'
'{a}'
>>> f'\{{a}\}'
File "<stdin>", line 1
SyntaxError: f-string: single '}' is not allowed
# doing it without f-strings
>>> '{' + a + '}'
'{hello}'
如何在 fstring 中转义字符?
f'{{{a}}}'
。 - jasonharper