在python2里面使用python3的print


在python2里面使用python3的print

在 2.6 版中,print 函数通过 __future__ 模块向后移植到 Python 2:

# 在 Python 2.6 及以上版本中
from __future__ import print_function
print("Hello", "world!")
> Hello world!

print 语句在 Python 3 中无法运行。如果你要输出内容,并希望在两个版本的 Python 中都可以,则需要在 Python 2 代码中导入 print_function


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM