寫第一個Python程序hello.py,內容僅有一句,print 'hello world',
運行 Python hello.py 出錯,提示:
File "<stdin>" , line 1
python hello.py
SyntaxError:invalid syntax
原因:
在shell腳本中,運行shell腳本命令;在Python命令行中,運行Python代碼。然而,“python hello.py”是一個腳本命令,不是python代碼。
因此,退出python命令行,直接cd到hello.py所在目錄,運行python hello.py,即可。
若是非要在python命令行中運行,輸入print("hello world")即可。