在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