Skip to main content
 首页 » 编程设计

python之在 Python 2.7.11 中默认打印一个函数

2025年05月04日15youxin

<分区>

前几天不小心写了

print("a function?") 

在我的 Python 2.7.11 控制台中,我很惊讶它会工作而不是抛出错误。我假设,有一个隐式的

from __future__ import print_function 

尝试过

print "also a statement???" 

这也奏效了!请注意,当从 __future__ 导入时,该语句被禁用。它实际上被禁用了,只有当我导入 print_function

时函数 sytax 才起作用

我在文档中找不到任何内容,Python docs仍在阅读:

Note: This function is not normally available as a built-in since the  
name print is recognized as the print statement. To disable the  
statement and use the print() function, use this future statement at  
the top of your module: (...) 

我错过了什么?为什么 print 是一个语句而是 Python 2.7 中的一个内置函数?