def funn(arg1, arg2=[]):
print(id(arg2))
arg2.append(arg1)
print(arg2)
funn(1) # here you will get printed an id of arg2
funn(2, [3, 4]) # here it's a different id of arg2 because it's a new list
funn(5) # here you will see that the id of the arg2 is the same as in the first function call.
关于这个here有一篇很好的文章。但为了更好地理解,我对你的函数做了一个小的修改,以便更好地将问题形象化
相关问题 更多 >
编程相关推荐