蟒蛇:
1>0 and print("yes")
Run Code Online (Sandbox Code Playgroud)
SyntaxError:'print'语法无效
谁能说出原因?谢谢!
Ash*_*ary 10
在Python 2中,print是一个语句,它不能用作表达式.
要在Python 2中使用Python 3的打印功能,您需要先导入它:
from __future__ import print_function
Run Code Online (Sandbox Code Playgroud)
演示:
>>> 1>0 and print("yes")
File "<ipython-input-2-0714eacbdec3>", line 1
1>0 and print("yes")
^
SyntaxError: invalid syntax
>>> from __future__ import print_function
>>> 1>0 and print("yes")
yes
Run Code Online (Sandbox Code Playgroud)