刚刚在windows 上安装了python ,想print 字符串,但是一直报错 (python 3.3 .2版本)
>>> print hello
SyntaxError: invalid syntax
>>> print 'hello'
SyntaxError: invalid syntax
>>> print "hello"
SyntaxError: invalid syntax
>>> print "hello";
SyntaxError: invalid syntax
>>> print (hello)
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
print (hello)
NameError: name 'hello' is not defined
>>> print ('hello')
hello
# 最后这个有效,好像和2.7版本的差别挺大的,不知道和不同平台有没有关系,之前一直在ubuntu上使用python
# 在ubuntu上,上面几种写法好像都支持
本文介绍在Python 3.3环境中正确使用打印功能的方法。针对初学者常见的语法错误进行了详细解释,并给出正确的示例。指出在Python 3.x中,print已成为一个函数,需要使用括号来包裹参数。
2628





