【发布时间】:2012-12-20 12:47:23
【问题描述】:
我有以下代码:
print '''
Hello World
''''
它适用于 Python 2,但不适用于 Python 3:
Python 3.2.3 (default, Dec 10 2012, 06:30:54)
[GCC 4.5.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print '''
... hello world
... '''
File "<stdin>", line 3
'''
^
SyntaxError: invalid syntax
>>>
我做错了什么?
【问题讨论】:
-
在python3中使用
print()作为函数。 docs.python.org/3.0/whatsnew/3.0.html#print-is-a-function -
您应该通读文档,了解 2 和 3 之间的变化,因为还有其他不太容易发现的重大变化。
标签: python python-3.x python-2.7 multiline