任何人都可以向我解释为什么a和b下面的两个函数表现不同.函数a在本地更改名称,b更改实际对象.
我在哪里可以找到这种行为的正确文档?
def a(names): names = ['Fred','George','Bill'] def b(names): names.append('Bill') first_names = ['Fred','George'] print "before calling any function",first_names a(first_names) print "after calling a",first_names b(first_names) print "after calling b",first_names
输出:
before calling any function ['Fred','George'] after calling a ['Fred','George'] after calling b ['Fred','Bill']