-6

I am a new learner to the Python language. When I want to print, I use the syntax:

print "hello world"

But when I use this syntax, it shows an error like missing parenthesis in calling print. I don't know why it is happening, because I know there is no need of using parentheses in Python to print a string like

print ("hello world")

What wrong have I done?

This is the error I get:

SyntaxError: Missing parentheses in call to 'print'

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
karthikmunna
  • 139
  • 1
  • 2
  • 14
  • try `print ("hello world")` in python 3.x print is a function not a statement – The6thSense Nov 03 '15 at 06:57
  • 1
    Probably you are using python 3.x. Try `python --version` in terminal to be sure. – Ahsanul Haque Nov 03 '15 at 06:58
  • 2
    "I know there is no need of using parenthesis" - "Missing parenthesis" – TigerhawkT3 Nov 03 '15 at 07:05
  • 2
    When the interpreter told you that you need parentheses for a print call, did you think it was playing a practical joke on you or something? – TigerhawkT3 Nov 03 '15 at 07:07
  • 3
    @TigerhawkT3, OP knew what is the right answer, he didn't know why this is the right answer. Probably, OP doesn't know the differences between python 2.x and 3.x. `did you think it was playing a practical joke on you or something?`- that phrase is unnecessarily rude and will demoralize new users to ask a question, though we can agree on the point that the question lacks research effort. – Ahsanul Haque Nov 03 '15 at 07:12
  • @AhsanulHaque - I think it's pretty clear that the OP is sure that he doesn't need parentheses on a `print()` call even though the interpreter says that he does. And I wasn't trying to be rude - many people really don't believe the interpreter, generally when it tells them it can't find a file with the specified name. – TigerhawkT3 Nov 03 '15 at 07:31

1 Answers1

2

Consider:

print "hello world"

The above statement is OK when you are using Python 2.x, because in Python 2.x, print is a statement.

But in Python 3.x, print is a function and there is no way to turn it back into a statement. So you must use parentheses.

So for Python 3.x, the answer is:

print("hello world")

Please refer to: Print Is A Function.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Andrés Pérez-Albela H.
  • 4,003
  • 1
  • 18
  • 29