I have the following code:
print '''
Hello World
''''
It works well with Python 2 but does not work with 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
>>>
What am I doing wrong?
In Python 3, the print statement is a function, and you need to use parentheses. Additionally, the triple single-quoted string is represented as '''
, not ''''
. Here’s the corrected version for Python 3:
print('''
Hello World
''')
Make sure to use parentheses with the print
function and the correct string representation.