新聞中心
在安裝了最新版本的python 3.x版本之后,去參考別人的代碼(基于Python 2.x寫的教程),去利用print函數(shù),打印輸出內容時,結果卻遇到print函數(shù)的語法錯誤:

專注于為中小企業(yè)提供成都做網站、成都網站設計服務,電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業(yè)亳州免費做網站提供優(yōu)質的服務。我們立足成都,凝聚了一批互聯(lián)網行業(yè)人才,有力地推動了成百上千家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網站建設實現(xiàn)規(guī)模擴充和轉變。
SyntaxError: invalid syntax
這是因為Python 2.x升級到Python 3.x,print函數(shù)的語法變化了,所以用Python 2.x的print函數(shù)的代碼,放在Python 3.x中運行,結果就出現(xiàn)了print函數(shù)的“SyntaxError: invalid syntax”了。
Python 2.x和Python 3.x中print函數(shù)語法方面的區(qū)別
最簡潔的解釋為:
Python 2.x: print “所要打印的內容” , 不帶括號
Python 3.x: print函數(shù)(”所要打印的內容”),必須帶括號
舉例來說明,即為:
1.不帶百分號格式化的
python 2.x:
print "Pyhon 2 can use print string without ()";
python 3.x:
print("Python3, print must use () to output string");2.帶百分號格式化的
python 2.x:
print "old %s version is %d, print no ()"%("Python", 2);python 3.x:
print("new %s version is %d, print must have ()"%("Python", 3)); 本文題目:創(chuàng)新互聯(lián)Python教程:python3print報錯
分享鏈接:http://www.5511xx.com/article/cdhcoip.html


咨詢
建站咨詢
