问题代码如下
In [9]: map.append(('1', '2'))
In [10]: for i, j in map:
....: print i, j
....:
1 2
In [15]: list = [1, 2]
In [16]: for i,j in list:
....: print i,j
....:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-16-2f2ad245c3f3> in <module>()
----> 1 for i,j in list:
2 print i,j
3
TypeError: 'int' object is not iterable
请问各位朋友 其中设计到什么细节,从文导致两种不同的结果?
for i,j in [1, 2]
迭代到的第一个值是1, 不能把1解包给i,j.因为1不是可迭代的for i,j in [(1, 2)]
迭代到的第一个值是(1,2),可以解包给i,j