我正在学习Python,甚至不能编写第一个例子:
print 2 ** 100
Run Code Online (Sandbox Code Playgroud)
这给了 SyntaxError: invalid syntax
指着2.
为什么是这样?我正在使用3.1版
TM.*_*TM. 225
这是因为在Python 3,他们已经取代了print 声明与print 功能.
语法现在或多或少与以前相同,但它需要parens:
来自" python 3中的新功能 "文档:
Old: print "The answer is", 2*2
New: print("The answer is", 2*2)
Old: print x, # Trailing comma suppresses newline
New: print(x, end=" ") # Appends a space instead of a newline
Old: print # Prints a newline
New: print() # You must call the function!
Old: print >>sys.stderr, "fatal error"
New: print("fatal error", file=sys.stderr)
Old: print (x, y) # prints repr((x, y))
New: print((x, y)) # Not the same as print(x, y)!
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
254029 次 |
| 最近记录: |