global_var = 1
def my_vars():
print( 'Global Variable:' , local_var )
local_var = 2
print( 'Local variable:' , local_var )
global inner_var
inner_var = 3
my_vars()
print( 'Coerced Global:' , inner_var )
答案 0 :(得分:1)
您在分配local_var
之前已引用print( 'Global Variable:' , local_var ) # did you mean global_var?
。你有什么期待?
{{1}}