Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
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 Jan 21 '13 at 23:19
add comment

3 Answers 3

up vote 12 down vote accepted

In Python3 print is a function:

print("Hello, World!")

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

share|improve this answer
    
And I now feel like a nooblet. Thanks for helping me out! –  Switchkick Nov 4 '10 at 11:22
2  
Yeah. This is going to cause me a shedload of issues when Ubuntu (or me on my own) finally moves to Python 3.x –  Oli Nov 4 '10 at 11:23
4  
The "2to3" tool should easily fix this ones. –  João Pinto Nov 4 '10 at 11:42
add comment

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

print('Hello World')

That should work.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.