安装好 python-3.6.8rc1 executable installer
Python Releases for Windows www.python.org
运行CMD,执行python,
写第一个Python程序内容仅有一句,print 'hello world',
运行print "hello world"出错,提示:
C:\windows\system32>python
Python 3.6.8rc1 (v3.6.8rc1:cc3e73212a, Dec 11 2018, 23:24:16) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print "hello world"
File "<stdin>", line 1
print "hello world"
^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print("hello world")?
原因:
在shell脚本中,运行shell脚本命令;在Python命令行中,运行Python代码。然而,print("hello world")是一个脚本命令,不是python代码。
因此,退出python命令行,直接cd到hello.py所在目录,运行python hello.py,即可。
若是非要在python命令行中运行,输入print("hello world")即可。