【发布时间】:2016-05-07 03:39:02
【问题描述】:
从我的 Python 控制台
>>> numbers = [1,2,3]
>>> [print(x) for x in numbers]
1
2
3
[None, None, None]
为什么最后会打印三个无?
【问题讨论】:
-
因为
print()是python3中返回None的函数 -
Python 解释器总是打印您输入的任何表达式的值。如果您将其更改为
r = [print(x) for x in numbers],您会看到r现在包含[None, None, None]。
标签: python