Python 一个奇特的引用设定

def f(x):
    print 'original'
    if x > 0:
        return f(x-1)
    return 0
g = f
def f(x):
    print 'new'
    return x
print g(5)

结果是:

original
new
4

证明了:

1.when g(5) runs, origninal `f`is called,not new `f`.
2.as 5>0,'return f(x-1)'is executed 3.new`f`is called when `f(x-1)` runs. so the result is 4.
posted @ 2013-12-27 11:23  LisPythoniC  阅读(156)  评论(0编辑  收藏  举报