python - List comprehension returning values plus [None, None, None], why? -


this question exact duplicate of:

im studying comprehensions. print(x) part (i think. prints value of x passes 'in' test) why returning list of none afterward?

>>> g ['a', 'x', 'p']  >>> [print(x) x in g] x p [none, none, none] #whats this?  

you use list comprehension print items in list, , list printed. try assigning list variable instead.

>>> g ['a', 'x', 'p']  >>> x = [print(x) x in g] x p # 

now list in x , isnt printed. list still there...

>>> print(x) [none, none, none] >>> x [none, none, none] 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -