它如何在引擎蓋下工作?我不明白下面的錯誤的原因:python:我什麼時候可以解開一個發生器?
>>> def f():
... yield 1,2
... yield 3,4
...
>>> *f()
File "<stdin>", line 1
*f()
^
SyntaxError: invalid syntax
>>> zip(*f())
[(1, 3), (2, 4)]
>>> zip(f())
[((1, 2),), ((3, 4),)]
>>> *args = *f()
File "<stdin>", line 1
*args = *f()
^
SyntaxError: invalid syntax
您是否在尋找[ 'itertools.consume'](http://docs.python.org/library/itertools.html#recipes)? – katrielalex
我想他可能正在尋找'list(f())'或'tuple(f())'。 –
對不起,我更想知道* Generator如何工作,以及在哪裏可以使用它。 –