List comprehension returning values plus [None, None, None], why? [duplicate]

print is a function (in Python3). It prints something to the screen, but returns None.

In Python2, print is a statement. [print(x) for x in g] would have raised a SyntaxError since only expressions, not statements, can be used in list comprehensions. A function call is an expression, which is why it is allowed in Python3. But as you can see, it is not very useful to use print in a list comprehension, even if it is allowed.

Leave a Comment