python - Python中的 'print'是什么?

标签 python

我了解 print 的作用,但该语言元素是什么“类型”?我认为是一个函数,但是为什么会失败呢?

>>> print print
SyntaxError: invalid syntax

print 不是函数吗?它不应该打印这样的东西吗?

>>> print print
<function print at ...>

最佳答案

在 2.7 及以下版本中,print 是一个语句。在 python 3 中,print 是一个函数。要在 Python 2.6 或 2.7 中使用打印功能,您可以这样做

>>> from __future__ import print_function
>>> print(print)
<built-in function print>

this section来自 Python 语言引用,以及 PEP 3105为什么会改变。

关于python - Python中的 'print'是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7020417/

相关文章:

python - 如何在 python pandas 中获取多级索引中的一个系列

python - 具有不同 x 和 y 编码的 Altair 选择

python - Pygame 有点滞后。是不是因为计算次数太多了?

python - 如何抑制结果中显示的 Tensorflow 警告

Python 脚本输出没有出现在 CMD 中

python - 比较运算符无法识别两个相同的数字

python - 监控和重启python脚本的最佳方法

python - Knn 分类器的 Scikit learn 中出现“不支持多类多输出”错误

python - 动态嵌套循环-递归

Python:AttributeError: '_io.TextIOWrapper' 对象没有属性 'split'