也叫内部函数
#!/usr/bin/env python
def outer(a):
i = a + 1
def inner():
j = i + 1
def innest():
print "innest: i=%d,j=%d" % (i, j)
innest()
inner()
outer(1)
$ python t.py
innest: i=2,j=3
#!/usr/bin/env python
def outer(a):
i = a + 1
def inner():
print "inner: i=%d" % i
return inner
foo = outer(1)
foo()
$ python t.py
inner: i=2