0

I am trying to do Hello World in Python but:

 print "Hello World"

keeps giving me a syntax error. Why is this, i am using python 3.2...

Dharman
  • 30,962
  • 25
  • 85
  • 135
Billjk
  • 10,387
  • 23
  • 54
  • 73
  • Were you following a tutorial or just trying to do hello world? If you were following a python 3.2 tutorial, I would think it would show the proper print() syntax – jdi Mar 25 '12 at 21:13
  • The example you've given is perfectly valid for all versions of Python prior to version 3.0; In classic Python print was a statement rather than a function. In Python 3.0 and later print is a function, and thus requires that you enclose its argument list in paretheses. In fact the only way that Python's interpreter knows that it should treat a word as a callable object (function, method, class instantiation, etc) is by the presences of the subsequent () expression. The old treatment of print, as a statement, was a wart and one that Guido had wanted to remove for a long time. – Jim Dennis Mar 25 '12 at 21:18

2 Answers2

7

In Python 3.2, print is a function.

print("Hello World")
Makoto
  • 104,088
  • 27
  • 192
  • 230
4

Use:

print("Hello World")

That is a Python 3 command, while

print "Hello World" 

is a Python 2 command

If the book that you are using only has Python 2 things, get a new book!

Billjk
  • 10,387
  • 23
  • 54
  • 73