阅读背景:

作为函数的输入传递的python字典在该函数中表现为全局而不是本地

来源:互联网 

I am very confused by the behaviour below. Cases 1, 3, and 4 perform as I would expect, but case 2 does not. Why does case 2 allow the function to change the value of the dictionary entry globally, even though the dictionary is never returned by the function? A main reason I am using functions is to isolate everything in the function from the rest of the code, but this does not seem to be possible if I choose to use the same variable names inside of the function. I was under the understanding that anything explicitly defined in a function is local to that function, but this does not seem to be the case if the dictionary is I am very confused by the behaviour below. Case




你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: