是的,您在这里不正确。函数定义引入了新的范围。
# coding: utf-8def test(): var = 1 def print_var(): print var <--- var is not in local scope, the var from outer scope gets used print_var() print vartest()# 1# 1def test1(): var = 2 def print_var(): print var <---- var is in local scope, but not defined yet, ouch var = 3 print_var() print vartest1()# raise Exception
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)