Python print "hello world" SyntaxError: invalid syntax


剛安裝Python,在IDLE中輸入print “Hello World”,誰知卻發生錯誤:

>>> print "Hello World"
SyntaxError: invalid syntax

而在朋友的機子上測試卻運行無誤,經查得知這是Python 版本不同所致。朋友用的是2.x版本,而我用的是3.x版本

正確命令:print("Hello World")

問題是通過用help命令解決的。輸入help(print)就知道print的正確用法了。

>>> help(print)Help on built-in function print in module builtins:
print(...)    print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)        Prints the values to a stream, or to sys.stdout by default.    Optional keyword arguments:    file:  a file-like object (stream); defaults to the current sys.stdout.    sep:   string inserted between values, default a space.    end:   string appended after the last value, default a newline.    flush: whether to forcibly flush the stream.

 

2013-07-26 15:13:28

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM