Generator comprehension - list None

Bob Gailer bgailer at gmail.com
Tue Oct 18 07:57:59 EDT 2016


On Oct 18, 2016 7:45 AM, "Sayth Renshaw" <flebber.crue at gmail.com> wrote:
>
> I was solving a problem to create a generator comprehension with 'Got '
and a number for each in range 10.
>
> This I did however I also get a list of None. I don't understand where
none comes from. Can you please clarify?
>
> a = (print("Got {0}".format(num[0])) for num in enumerate(range(10)))
>
The comprehension collects the values of the 10 calls to print(). print()
always returns None.

> # for item in a:
> #       print(item)
>
> b = list(a)
> print(b)
>
> Output
> Got 0
> Got 1
> Got 2
> Got 3
> Got 4
> Got 5
> Got 6
> Got 7
> Got 8
> Got 9
> [None, None, None, None, None, None, None, None, None, None]
> => None
>
> Thanks
>
> Sayth
>
> --
> https://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list