<p>我想学习zip类的功能。我写了一个非常简单的例子。在</p>
<pre><code>>>> names = ['name1','name2','name3']
>>> ages = ['age1','age2','age3']
>>> print(zip(names, ages))
<zip object at 0x03DB18F0>
>>> zipped = zip(names, ages)
for i in zipped:
type(i)
print(i)
</code></pre>
<p>结果是(正如预期的那样)—</p>
^{pr2}$
<p>但是如果我在这一行后面写下:</p>
<pre><code>for i in zipped:
print(i)
</code></pre>
<p>它编译但不打印任何内容!在</p>
<p>我又检查了一遍-</p>
<pre><code>>>> zipped = zip(names, ages)
>>> for i in zipped:
print(i)
('name1', 'age1')
('name2', 'age2')
('name3', 'age3')
</code></pre>
<p>这次打印正确。但是在解压的时候-</p>
<pre><code>>>> names2, ages2 = zip(*zipped)
Traceback (most recent call last):
File "<pyshell#29>", line 1, in <module>
names2, ages2 = zip(*zipped)
ValueError: not enough values to unpack (expected 2, got 0)
</code></pre>
<p>由于某种原因,<code>zipped</code>变量似乎变空了?在</p>
<blockquote>
<p>Note: if required you may change the title of the question. I am using python 3.6.1 on a windows (10) machine.</p>
</blockquote>