关于python闭包的问题 ,求大佬指点

为什么第一个得出的结论是 6,6 ,而第二个结果是6,7  
我调试第一个的的时候把test函数完整的执行了两遍,因为每次都要初始化x=5,所以才会出现结果都是6

调试第二个的时候先执行a = funX(),这时候就会得到一个返回值funY,由于没有加( ),所以funY这时候并不会执行,程序再往下,就是执行两次a(),这两次a()就是在执行funY(),每次都会叠加,所以得出的值6,7。 

关于这两个解释,有什么问题吗? 

还有一个不懂的就是上面就是标粗的地方,我觉得a( )执行的时候,就相当于funX( )( ),先执行funX(),然后再执行funY(),执行funX()的时候还是初始化x了又是等于5

http://img3.mukewang.com/5e5b37f40001278202860555.jpg

慕码人3612724
浏览 734回答 0
0回答

慕斯4360584

ZTQQRQQECZMAJFYEIYHOTZFRXLKYQRBKJBAMSSIEEOBHZOANTQCFPSZBDPFXHQAAUNGIKXNAZWFJZVHNNGXDDTTFJKJXRZFVVZFYAOKBOKJZTJGSYEKHRUDFIYDCJSWPIEYRWZEOOVMSFICEZPSBZAQAEKXPZZJWSBLEEFZMMSZPFLOLAFLBUHRUEVBJBRELCVOXBRLHDKAADTZURYUBYEHFYFDJZHNQDDMMVZLZISOOBIOYOYPHDTAGMNNHQOUDGGKBEQKQSEOVRYYCMFCBCMVYFVLULOGOFCFFZQDDAFWSPJQJFQKHYLOIZQKOOIUMPZWNGSJGAHMHRSFKKLVZCDJMWAXNGQAMDXVYSIFLUOYRUQDAHUROICKGDGKCIBSSFKGBOBISLHWZRXUQFZZJMWQZLUOBUNDMGHUKTGDTGENBOMZCIJPHXHPCHUNXDKUQNOZXTAGTDOYRSVLRNHRUNHKLYLSVKTOUENOHTZBPVOVOYPMGJMSZMEHOGRCUNCZCCMSTWSXAHUHBFFTVXXOKJMHVOQDOAJKNEWGGQDYXJNQDXEAMZAZAKBUDXXBIZLLEBJZFFOZQHTHSRPPPZMOUXJXKQMJTGIRNXWJCMZZDXTUUZPJZCDAAGCSPCGCVYRQFVJUBRULIJBQHAUYLMTNEHKUBBFIFEISDCLFFPC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