0

Possible Duplicate:
Syntax error on print with Python 3

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?

Community
  • 1
  • 1
romaninsh
  • 10,606
  • 4
  • 50
  • 70
  • use `print()` as a function in python3. http://docs.python.org/3.0/whatsnew/3.0.html#print-is-a-function – Ashwini Chaudhary Jan 06 '13 at 17:52
  • 1
    You should read through the docs on what has changed between 2 and 3, because there are other significant changes that are less easy to stumble upon. – Katriel Jan 06 '13 at 18:23

1 Answers1

2

It's not a problem of multi-line, but a problem of print.

print was replaced with a function print() in python 3, so that you have to call it as a function.

  • won't work in Python 3: print 'hello'
  • the one works instead: print('hello')

For your case, try

print('''
Hello, 
World
''')
Timothy
  • 4,467
  • 5
  • 28
  • 51