【发布时间】:2014-01-10 05:28:07
【问题描述】:
我正在尝试使用不完整的 kwargs 格式化字符串,如下所示:
input is like "{key1} {key2} {key3}"
output will be like "value1 value2 {key3}"
我在下面试试,
>>> "{key1} {key2} {key3}".format(key1='value1', key2='value2')
但出现以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'key3'
你知道什么是最好的方法吗?
【问题讨论】:
标签: python