import sys
a = 11
init_cnt = sys.getrefcount(a) - 1
print "init", init_cnt
####init 22
def function(c):
print 'in function, count: ', sys.getrefcount(c) - 1
####in function, count: 24
print '函数调用,计数器增加', sys.getrefcount(c) - 1 - init_cnt
####函数调用,计数器增加 2
function(a)
After passing a as a parameter to function, it is referenced twice:
You can see that parameter a is referenced by two attributes in the function object.