>>> "%(1)s" % {1:'a',2:'b'}
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: '1'
下面这个就可以,为什么?
>>> "%(1)s" % {'1':'a','2':'b'}
'a'
阿神2017-04-17 15:37:57
KeyError应该类型错误。
我试过
"%(1)s" % {'3': 'a', '2': 'b'}
还是报原来的错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: '1'
看了这个%(1)s
中的1
是为了匹配key
值的。