F 字符串中允许使用哪些文字字符?

What are allowed as literal characters in f-strings?

formatted string literals (f-strings) 的 BNF 规则中:

f_string ::= (literal_char | "{{" | "}}" | replacement_field)*
...
literal_char ::= <any code point except "{", "}" or NULL>

NULL具体是什么意思?

看起来f'[=11=]'有效。

允许的 代码点 any code point except "{", "}" or NULL

字符串f"[=12=]"包含两个代码点\0。它们形成一个转义序列,代表一个空字节——就像\n代表一个换行符。这类似于 源代码(字符串)True 表示布尔真值(对象)的方式。
值得注意的是,这些表示并不是它们所代表的东西。将 [=17=] 放在 f 字符串中很好,因为它本身不是 NULL。

>>> # the source code representing a number is not the number
>>> source = "1337"
>>> eval(source) == source
False

请注意,CPython 和 PyPy 不接受源代码中的 NULL 字节开头。