我的代码:
#!/usr/bin/env python
def Runaaall(aaa):
Objects9(1.0, 2.0)
def Objects9(aaa1, aaa2):
If aaa2 != 0: print aaa1 / aaa2
Run Code Online (Sandbox Code Playgroud)
我收到的错误:
$ python test2.py
File "test2.py", line 7
If aaa2 != 0: print aaa1 / aaa2
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)
我不知道为什么会发生这种错误.
Ste*_*202 16
if 必须用小写字母书写.
此外,
if在单独的行上写下一个-clause 的主体.既然你刚刚开始学习Python,你可能想要熟悉围绕参数编写括号print,因为从Python 3开始,print是一个函数,而不是关键字.
要在Python 2.6中强制实施此语法,您可以将其放在文件的顶部:
from __future__ import print_function
Run Code Online (Sandbox Code Playgroud)
示范:
>>> print 'test'
test
>>> from __future__ import print_function
>>> print 'test'
File "<stdin>", line 1
print 'test'
^
SyntaxError: invalid syntax
>>> print('test')
test
Run Code Online (Sandbox Code Playgroud)
有关__future__导入的更多信息,请参阅文档.