当在 Python 脚本中遇到对象时,就会创建对象。Python 中没有任何东西被提升,没有变量,没有函数,什么都没有。
所以这不起作用:
print(foo()) # NameError: name 'foo' is not defined
def foo():
return 'hello'
Run Code Online (Sandbox Code Playgroud)
虽然这确实:
def foo():
return 'hello'
print(foo()) # 'hello'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2117 次 |
| 最近记录: |