プログラミング言語Pythonの str.format や f-string*1 において、書式指定子部のみ1段階の入れ子が許容される。下記コードではいずれも文字列 Hello!!!!!
が得られる。
msg = 'Hello' '{:!<10}'.format(msg) f'{msg:!<10}' f, a, w = '!', '<', 10 '{:{}{}{}}'.format(msg, f, a, w) f'{msg:{f}{a}{w}}' # 各typeフィールドを明示 f'{msg:{f:s}{a:s}{w:d}s}'
Top-level format specifiers may include nested replacement fields. These nested fields may include their own conversion fields and format specifiers, but may not include more deeply-nested replacement fields. The format specifier mini-language is the same as that used by the string .format() method.
Lexical analysis, Formatted string literals
*1:formatted string literal