我有以下代码:
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
>>>
我做错了什么?
不是多线的问题,而是
print
的问题。
在 python 3 中,print
被替换为函数 print()
,因此您必须将其作为函数来调用。
print 'hello'
print('hello')
针对您的情况,请尝试
print('''
Hello,
World
''')