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 开发者_Go百科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
>>>
You're using python 3. In python 3 print
is a function
print ("test")
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.
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
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
""")
精彩评论