3

All I wrote in the interpreter was as follows:

>>> print "Hello, World!"
  File "<stdin>", line 1
    print "Hello, World!"
                        ^
SyntaxError: invalid syntax

How did I even get an error? All I tried to do was run a print command.

Flimm
  • 41,766
Switchkick
  • 3,883
  • 1
    I've edited out your second question. If you still want the answer to that question, go ahead and ask it in a separate question post. – Flimm Jan 21 '13 at 22:12
  • This is a basic programming in Python syntax question. It probably isn't appropriate for AskUbuntu. – Ken Kinder Jan 21 '13 at 23:19

4 Answers4

13

In Python3 print is a function:

print("Hello, World!")

Check: http://docs.python.org/release/3.0.1/whatsnew/3.0.html

João Pinto
  • 17,159
3

One of the major changes in Python 3 is that print has become a function. Try using:

print('Hello World')

That should work.

Seth
  • 58,122
3

Python 3 has changed print from being a statement to being a function. This is how you print "hello world" in Python 3:

print("Hello world")

I recommend taking a look at What's new in Python 3, this issue is the first one mentioned on the list.

I also recommend asking any programming questions on StackOverflow, in my experience, they are welcoming to beginners.

Flimm
  • 41,766
0

Some of the other answers have already covered this, but you should do print("Hello World") instead. The reason why it's been changed in python 3 is to allow keyword arguments such as end (to change the default newline end`) among others.

Example:

print("Hello World", end="") # will print an empty character at the end, not a newline