我刚刚在一台新机器上安装了3.4,尝试运行我知道有效的东西并且失败了。然后我尝试将以下内容键入IDLE并失败:
>>> print 'hello'
SyntaxError: invalid syntax
>>> print hello
SyntaxError: invalid syntax
>>> print "hello"
SyntaxError: invalid syntax
>>>
我很困惑为什么会失败。
答案 0 :(得分:2)
The print statement has been replaced with a print() function, with keyword arguments to replace most of the special syntax of the old print statement (PEP 3105).
所以试试:
print ("hello")
答案 1 :(得分:1)
我相信Python 3+你需要parens。试试这个:
print("Hello")
这是我的测试:
Python 3.3.2 (default, Sep 15 2013, 13:36:01)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print 'hello'
File "<stdin>", line 1
print 'hello'
^
SyntaxError: invalid syntax
>>>
>>>
>>> print("Hello")
Hello
>>>