Why is a generator expression called a expression?
Chris Angelico
rosuav at gmail.com
Mon Apr 20 06:45:23 EDT 2020
On Mon, Apr 20, 2020 at 8:26 PM Veek M <veek at dont-use-this.com> wrote:
>
> but one can do the following
> (x for x in 'apple').next() * 2
>
> def foo():
> (yield 2)
> foo().next() * 3
>
> (lambda x: 2)()*4
>
> generator expr, yield expr, lambda expression
> all require some modification (insertion of a .next or explicit () so
> it's quite confusing..
>
I don't know what you mean by "modification", but the lambda
expression has a value - and that value is a function. When you call
that function, you get another value, which is whatever the function
returned. Same with a generator expression.
Also, I recommend upgrading to Python 3. Python 2 is end-of-life.
ChrisA
More information about the Python-list
mailing list