j=i # ref count = 2 on the shared object
—-Now look at lists. Do lists hold items by value or reference? More specifically,
– Add() by pbref? yes according to many posts in this blog and also [[python essential ref]]
– Read() by pbref? Yes. pbclone would make myList.edit() meaningless.
– qq(mylist = ….) is by reference? Probably yes, otherwise counter-intuitive.
How do you verify? How about id(mylist). Note
id( i )
arr.append(i) # pbref. Ref count = 2
id( arr )
i=2 # Rebinding! not “content edit”. i now points to a new object, so ref count = 1 on the original object! Counter-intuitive to me.
arr = 2.1 # Rebinding, not “content edit”. arr now points to a new object, so ref count = 0 on the original object “1.9”
id( arr )
Q: is it possible to change the value of arr?
A: arr currently points to an int object. We can rebind this pointer to a “9.89” object. However, if you want to change pointee object content at arr, then it depends on the pointee object type. For integer objects, content is immutable, so answer is NOWAY.