Python:Triple Double Quote字符串格式

use*_*968 3 python python-3.x

我收到以下错误,我该如何解决?

KeyError:'a'过程以退出代码1结束

s = """
a b c {a}
""".format({'a':'123'})

print s
Run Code Online (Sandbox Code Playgroud)

MSe*_*ert 6

您需要按名称传递参数.format(a=123)或使用format_map需要字典的参数:

s = """
a b c {a}
""".format_map({'a':'123'})
Run Code Online (Sandbox Code Playgroud)