I'm confused by the following in Python 3.3:
>>> def foo(gen=False):
... if not gen:
... return list(range(10))
... else:
... for i in range(10):
... yield i
...
>>> foo()
<generator object foo at 0xb72a016c>
>>> foo(gen=False)
<generator object foo at 0xb72a0144>
>>> foo(gen=True)
<generator object foo at 0xb72a089c>
>>>
What am I misunderstanding? If gen
is False, the default value, then not gen
is True
, and thus I should get a list of integers [0,1,2,3,4,5,6,7,8,9]
. On the other hand, if it is True
, shouldn't (not gen) == False
result in a generator?