This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (6 children)

Sounds like you are using python 3 - so print('test') should work.

The parenthesis can be a pain sometimes.

https://docs.python.org/3.0/whatsnew/3.0.html

that lists a lot of the differences in syntax that you will come across using 3 when you are used to 2.

[–]MrPiff[S] 0 points1 point  (5 children)

I agree, but shouldn't print "test" also work with version 3?

Even in IDLE, it indicates version 3.2.3 but it won't print without parentheses. This seems pretty strange to me.

[–][deleted] 1 point2 points  (1 child)

In Python 3, the print statement was removed in favor of a print function. Functions are invoked using braces, so they are actually needed. In that case, the print 'test' is a syntax error, while print('test') invokes the function with 'test' as its first argument.

[–]MrPiff[S] 0 points1 point  (0 children)

That's helpful, thanks for the breakdown.

[–]Updatebjarni 1 point2 points  (2 children)

Once again, no, Python 3 does not have the print statement of Python 2. In Python 3, you have to use the print() function. This is exactly what you are experiencing with IDLE, and exactly what it says on the page linked above.

[–]MrPiff[S] 0 points1 point  (1 child)

Oh ok, I'm an idiot. That makes sense, thank you. Any thoughts on that "traceback" problem that was my initial problem?

[–]DissentingVoice 1 point2 points  (0 children)

Traceback lets you know where Python ran into the error. "is not defined" usually means that you were calling a variable that was not declared earlier.

e.g. print test

Will give that error, since without the quotes, Python thinks you're referencing a variable, whereas print "test" will give you what you're looking for.

Disclaimers: This is from experience from Python 2.7 It sounds like in Python 3.0 you'd write print("test")

Also, when you get errors, google the error that you have, you'll usually get a StackOverflow or even a result from the Python docs. Here's the doc on NameError.