getrefcount(...)
getrefcount(object) -> integer
Return the reference count of object. The count returned is generally
one higher than you might expect, because it includes the (temporary)
reference as an argument to getrefcount().
共享引用
思考:
a = "3"
b = a
a = "spam"
这样输出b会是多少?
变量a引用了spam对象的内存空间,所有值钱对象3肯定是还有引用的,那么谁用呢就是变量b
a = 3
b = a
a = a + 3
L = [1,2,3]
L2 = L
L = 24
此时L2依然不会变,如果写下面的语句替换L=24
L[0] = 24
这样就更改了L2的值,因为列表L引用的是对象、L[0]是在原处修改了引用值,L与L2是共享引用的,所以L修改了第一个对象的引用,L2也会改变