Why is f'{{{74}}}' the same as f'{{74}}' with f-Strings? Why is f'{{{74}}}' the same as f'{{74}}' with f-Strings? python python

Why is f'{{{74}}}' the same as f'{{74}}' with f-Strings?


Double braces escape the braces, so that no interpolation happens: {{{, and }}}. And 74 remains an unchanged string, '74'.

With triple braces, the outer double braces are escaped, same as above. The inner braces, on the other hand, lead to regular string interpolation of the value 74.

That is, the string f'{{{74}}}' is equivalent to f'{{ {74} }}', but without spaces (or, equivalently, to '{' + f'{74}' + '}').

You can see the difference when replacing the numeric constant by a variable:

In [1]: x = 74In [2]: f'{{x}}'Out[2]: '{x}'In [3]: f'{{{x}}}'Out[3]: '{74}'