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.
上一篇:强化学习(十)Double DQN (DDQN)


下一篇:shell命令rm删除非空文件夹