2012-09-07 124 views
0

我做的蟒蛇120-1 PDF我不明白這個語法錯誤

這裏的Python的教程字節的指令:

Start your choice of editor, enter the following program and save it as helloworld.py

Example 3.2. Using a Source File

#!/usr/bin/python 
# Filename : helloworld.py 
print 'Hello World' 

(Source file: code/helloworld.py) Run this program by opening a shell (Linux terminal or DOS prompt) and entering the command python helloworld.py. If you are using IDLE, use the menu Edit -> Run Script or the keyboard shortcut Ctrl-F5. The output is as shown below.

Output

$ python helloworld.py 

Hello World 

我進入這個計劃付諸文字牧馬人並將其保存爲helloworld.py

然後我打開我的終端並輸入python helloworld.py。

我收到的語法錯誤:無效的語法

我又試圖helloworld.py也收到語法錯誤:無效的語法

誰能告訴我在哪裏出了錯?

+0

向我們展示您的文件的確切內容。 – Rohan

+1

你是否使用Python 3?在這個版本中'print'是功能。所以你必須寫'print('Hello World')'。 – MaxPowers

回答

7

您正在使用2.x文檔,但正在運行3.x.降級Python,或查找更新的材料。

#!/usr/bin/python 
# Filename : helloworld.py 
print('Hello World') 
+0

我正在運行Python 2.6 – user1625016

+0

然後你需要添加更多的細節問題。 –