The str.format() method and the Formatter class share the same syntax
for format strings (although in the case of Formatter, subclasses can
define their own format string syntax).
Format strings contain “replacement fields” surrounded by curly braces
{}. Anything that is not contained in braces is considered literal
text, which is copied unchanged to the output. If you need to include
a brace character in the literal text, it can be escaped by doubling:
{{ and }}.
最好是一个
format
字符串:注意使用
"""
三重引号而不是"
单引号来格式化多行字符串。在编辑:
如果原始字符串包含
{ }
,我们必须按照documentation对它们进行转义:你必须连接这些字符串。现在,
eval()
看到您传递了13个字符串,但是eval()
只接受一个字符串。所以就这样做吧:我在每个字符串后面添加了空格,以确保它们不会碰到对方。在
相关问题 更多 >
编程相关推荐