最佳答案
f-Strings are available from Python 3.6 and are very useful for formatting strings:
>>> n='you'
>>> f'hello {n}, how are you?'
'hello you, how are you?'
Reading more about them in Python 3's f-Strings: An Improved String Formatting Syntax (Guide). I found an interesting pattern:
Note that using triple braces will result in there being only single braces in your string:
>>> f"{{{74}}}" '{74}'
However, you can get more braces to show if you use more than triple braces:
>>> f"{{{{74}}}}" '{{74}}'
And this is exactly the case:
>>> f'{74}'
'74'
>>> f'{{74}}'
'{74}'
Now if we pass from two {
to three, the result is the same:
>>> f'{{{74}}}'
'{74}' # same as f'{{74}}' !
So we need up to 4! ({{{{
) to get two braces as an output:
>>> f'{{{{74}}}}'
'{{74}}'
Why is this? What happens with two braces to have Python require an extra one from that moment on?