Python 2.7.10 (default, Sep 17 2015, 03:50:35) [GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
>>> def f():
... return True
...
>>>
>>> a,b = f()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'bool' object is not iterable
vs
>>> def f():
... return 'True'
...
>>>
>>> a,b = f()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: too many values to unpack
Why the difference ?
a,b = f(),f()
? – Black Thunderdef f(): return "Tr"
then call it witha, b = f()
. In your first example, you can't unpack something non iterable, second example you're trying to unpack an iterable with 4 items into 2. – ggorlen