0

Can anyone tell me what is wrong with this? I'm getting a syntax error after the 2nd quote on the print line... It seems like this should work perfectly fine. Thanks

def main():
 print "blah"
 return
main()
asked Nov 22, 2010 at 1:30
6
  • Works fine for me, I am using Python 2.6.4 Commented Nov 22, 2010 at 1:31
  • Tell us what the syntax error is. Commented Nov 22, 2010 at 1:32
  • 1
    Syntax error on print? Are you using Python 3? print is a function, not a statement. Should be print("blah"). Commented Nov 22, 2010 at 1:32
  • ahhh yeah, I'm using Python 3... Commented Nov 22, 2010 at 1:34
  • 3
    I guess I should have went for the answer instead of the comment. Commented Nov 22, 2010 at 1:36

4 Answers 4

4

In case you're using Python 3, the print statement is gone in that version and you need to use the print() function.

See: http://docs.python.org/release/3.0.1/whatsnew/3.0.html#print-is-a-function

answered Nov 22, 2010 at 1:32
Sign up to request clarification or add additional context in comments.

Comments

4

You're using python 3.

use

print("blah")

The print statement turned into the print function in the transition.

answered Nov 22, 2010 at 1:33

Comments

1

Remember if your using python 2.x then to help with the transition you can always have

from __future__ import print_function

At the top of your code, this will convert print into a function meaning 2.x code can be written with

print('This')

And run happily

answered Nov 22, 2010 at 10:34

Comments

0

Posting the exact error you get would be very helpful. I'm going to assume that this is an indentation error though. Don't mix tabs and spaces.

answered Nov 22, 2010 at 1:32

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.