>>> "%(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 should be of typeError.
I tried
"%(1)s" % {'3': 'a', '2': 'b'}
Still report the original error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: '1'
I saw that the %(1)s
in this 1
is to match the key
value.