1. 程式人生 > >python print'hello' File "",line 1 print 'hello' SyntaxError:invalid syntax

python print'hello' File "",line 1 print 'hello' SyntaxError:invalid syntax

python print'hello' File"<stdin>",line 1 print 'hello'SyntaxError:invalid syntax 剛開始看Python,照著書上些了個hello,結果錯誤:

>>> print'hello'   File "<stdin>",line 1     print'hello'                ^ SyntaxError: invalid syntax

檢視3.0文件:http://docs.python.org/release/3.0.1/whatsnew/3.0.html,發現從3.0開始print改成了

print()。文件是這樣寫的:The print statement has been replacedwith a print()function, with keyword arguments to replace most of the specialsyntax of the old print statement (PEP3105).

print語句被print()方法代替,舊print語句中的特定的語法被引數代替。

所以呢,hello world!應該寫成這樣:print ("hello world!")

原文:https://blog.csdn.net/elvis_lfc/article/details/52411734