在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
。