Why is a generator expression called a expression?

Chris Angelico rosuav at gmail.com
Tue Apr 21 16:24:27 EDT 2020


On Wed, Apr 22, 2020 at 6:12 AM Barry Scott <barry at barrys-emacs.org> wrote:
>
>
>
> > On 20 Apr 2020, at 10:29, Veek M <veek at dont-use-this.com> wrote:
> >
> > On Mon, 20 Apr 2020 19:19:31 +1000, Chris Angelico wrote:
> >
> >> In the case of a genexp, the expression has a value which is a generator
> >> object. When you pass that to all(), it takes it and then iterates over
> >
> > but an object is NOT THE SAME as it's value! '2' is an object which
> > happens to have a value of 2 under certain contexts.. ergo a generator
> > object is returned by ( whatever ) and therefore NOT a value-to-be-used!
>
> In computer software there are lots of objects that are not simple things
> like the integer 2. All of these objects can be values and are called values.
>
> A value is not limited to only being integers for example.

In fact, languages like Python strengthen that: not only *can* all
objects be values, but they inherently *are* values. Everything that
can be put into a variable is a value, and that includes functions,
strings, bound methods, dictionaries, modules, types (classes), the
lot. Everything is an object and everything is a value.

It takes some getting-your-head-around, but it is immensely powerful
and convenient!

ChrisA


More information about the Python-list mailing list