What does <generator object <generator object <genexpr> at 0x0402C7B0> mean?

inhahe inhahe at gmail.com
Wed May 22 07:16:55 EDT 2019


Short answer: (some generator expression) is for iterating over, as others
have said. try this:
print([fruit for fruit in favorite_fruits])

a loop would work too, as someone mentioned, but the result would be
different. you'd get your fruits separated by line breaks (or something
else if you specify that), and with no quotation marks, instead of in list
form.

also note: print(favorite_fruits) will do the same thing as print([fruit
for fruit in favorite_fruits]) so there's no need to put a list
comprehension there.

On Tue, May 21, 2019 at 9:16 PM CrazyVideoGamez <jasonanyilian at gmail.com>
wrote:

> I tried doing a list comprehension. I typed:
>
> favorite_fruits = ['watermelon', 'blackberries']
> print(fruit for fruit in favorite_fruits)
>
> And I got:
>
> <generator object <genexpr> at 0x0402C7B0>
>
> What does this mean and what do I have to fix?
> --
> https://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list