Skip to content Skip to sidebar Skip to footer

Escaping Chars In F-string

I have run into the following issue with the f-string: >>> a='hello' # how to print '{hello}' ? >>> f'{{a}}' '{a}' >>> f'\{{a}\}' File '

Solution 1:

You need triple braces:

f'{{{a}}}'

The two outer {}s "escape" and evaluate to {...}, then the inner {} is used for formatting (or at least that's how I interpret it).

Post a Comment for "Escaping Chars In F-string"