-1

I am learning a tutorial for Python language and trying to write a basic "Hello World!" program.

But when I do all steps described in the book I receive an error.

>> print "Hello World!"

SyntaxError: Missing parentheses in call to 'print'

Why I am getting this error?

Is my book wrong?

baldr
  • 2,891
  • 11
  • 43
  • 61

2 Answers2

2

it seems that you're using Python 3.x.

In python 3.x, the print statement is a function and you need to use it as a function like this

print("Hello World!")

mugabits
  • 1,015
  • 1
  • 12
  • 22
1

Your book is right, but might be outdated a bit. It seems it describes Python version 2, but you try to run your example on the version 3.

Python 3 has changed some features and this one is the most annoying to switch from P2 to P3.

"print" statement changed to function rather than operator as was in P2.

Calling function you should always use parentheses.

So, if you want to run your program in Python3 you should call it:

print("Hello World!")

And that's it.

If you want to use examples from your book as is - install Python2 and it should work.

baldr
  • 2,891
  • 11
  • 43
  • 61
  • 3
    Oh my, so many answers within 5 minutes! I'll accept this one, but thanks to everyone! –  Sep 30 '16 at 15:44