def outer(x):
def inner(i): #assign in outer's local
print (i) #i is in inner local
if i:inner(i-1):#not in my local or global
inner(x)
>>outer(3)
trackback......
NameError
def outer(x):
global inner
def inner(x): #assign in enclosing module
print (i)
if i: inner(i-1)#found in my global scope now
inner(x)
>>outer(3)
3 2 1 0
沒有留言:
張貼留言