打印在Python 3.3中不起作用?

时间:2013-10-07 09:38:32

标签: python

我在Visual Studio Professional 2013 RC中运行Python。我已经安装了{3.3}附带的the Python Tools for Visual Studio

我只是在做一个非常简单的print语句,但它会报告语法错误。

print 'aaa'

此外,在我输入 Enter 后,解释程序拒绝打印aaa。 截图如下:

enter image description here

来自解释器的

错误消息

>>> print '1
... '
... 
Traceback (most recent call last):
  File "C:\Program Files\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Python Tools for Visual Studio\2.0\visualstudio_py_repl.py", line 627, in run_one_command
    self.execute_item()
  File "C:\Program Files\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Python Tools for Visual Studio\2.0\visualstudio_py_repl.py", line 601, in execute_code_work_item
    code = compile(self.current_code, '<stdin>', 'single', self.code_flags)
  File "<stdin>", line 1
    print '1
           ^
SyntaxError: EOL while scanning string literal
>>> a=1
>>> print a
Traceback (most recent call last):
  File "C:\Program Files\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Python Tools for Visual Studio\2.0\visualstudio_py_repl.py", line 627, in run_one_command
    self.execute_item()
  File "C:\Program Files\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Python Tools for Visual Studio\2.0\visualstudio_py_repl.py", line 601, in execute_code_work_item
    code = compile(self.current_code, '<stdin>', 'single', self.code_flags)
  File "<stdin>", line 1
    print a
          ^
SyntaxError: invalid syntax
>>> 

我曾经玩过Python 2.7。为什么在3.3中呢?

1 个答案:

答案 0 :(得分:9)

print is no longer a statement in Python 3,它是函数 print(),因此正确的语法是:

print('aaa')