python ValueError: too many values to unpack 2018-10-12

一般情况下这种情况出现在字典中,如下:

a_dict = {'name':'levin','job':'teacher'}
for k,v in a_dict:
... print k,v
...
Traceback (most recent call last):
File "", line 1, in
ValueError: too many values to unpack
正确写法:
a_dict = {'name':'levin', 'job' : 'teacher'}
for k,v in a_dict.items():
print k,v

你可能感兴趣的:(python ValueError: too many values to unpack 2018-10-12)