Printing using list comprehension

后端 未结 10 1736
一生所求
一生所求 2020-12-03 10:58

From my Python console

>>> numbers = [1,2,3]
>>> [print(x) for x in numbers]
1
2
3
[None, None, None]

Why does this print

10条回答
  •  再見小時候
    2020-12-03 11:57

    print is a function in Python 3, which returns a None. Since you are calling it three times, it constructs a list of three None elements.

提交回复
热议问题