0

I've just installed Python 3.1.3 and tried to run the most basic of prints from the Python Shell. Below is a c/p of the shell. I'm lost already. Why is that a syntax error? Judging by the stuff here it shouldn't be.

Python 3.1.3 (r313:86834, Nov 27 2010, 17:20:37) [MSC v.1500 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.

>>> print "test"
SyntaxError: invalid syntax
>>> print 'test'
SyntaxError: invalid syntax
>>> 
bcmcfc
  • 25,966
  • 29
  • 109
  • 181

4 Answers4

6

You're using python 3. In python 3 print is a function

print ("test")
Falmarri
  • 47,727
  • 41
  • 151
  • 191
  • That sounds like an enormous change to make from one version to another! Which version of Python would you recommend a newbie learn? – bcmcfc Jan 13 '11 at 21:28
  • 4
    To be honest? I'd say to learn Python 2. Yes, Python 3 is the future, but its a long way away, and most of the books, tutorials, and online resources extant today are focused on Python 2. Once you've learned Python 2, and are familiar with the concepts, you can move to Python 3, and acquaint yourself with the changes in syntax and standard libraries. – quanticle Jan 13 '11 at 21:31
  • @bcmcfc: Which one to learn is a question that's asked quite a bit. Python 3 is starting to get support now, but I guess it'll be a couple of years before it's mainstream. So if you want to do a serious project soon, Python 2. If it's just for interest, feel free to go straight for Python 3. – Thomas K Jan 13 '11 at 23:01
  • I disagree that you should use python3x if it's just for interest. There's much more in the way of learning resources for python2x. – Wilduck Jan 14 '11 at 00:14
2

You're running Python 3, in which print is a function. So what you need to do is

print("Hello World")

EDIT: You're looking at the documentation for Python v2.7. Python 3 has many changes and is not backwards compatible with Python 2. The Python 3 docs are here.

quanticle
  • 4,872
  • 6
  • 32
  • 42
2

In Python 3 the print statement has been replaced by a print() function.
Try print("test").

There's more information here, basically Python 3 is intentionally backwards incompatible with previous versions of python. If you'd rather just follow through those tutorials consider installing Python 2.7

dabhaid
  • 3,849
  • 22
  • 30
0

Yeah just put parentheses/ () around the quotation marks.

print("test")

You have to do it whenever you print and when doing triple quoted strings.

Example of a triple quoted string:

print ( """

You can type whatever  any where here

""")
IP25
  • 1
  • 2