I am new at programming and I have a very basic question that I still don't understand.
As far as I understand, everything is an object in Python and variables just point to an object. If an object is changed, all variables that point to that object will show the change.
with a list it makes sense:
nums = [1,2,3]
a = nums
nums.append(4)
print(id(a))
print(id(nums))
Both a
and nums
point to the same object.
What I don't understand is why with numbers it's different?
nums = 1
a = nums
nums += 1
print(id(a))
print(id(nums))
How can we know which object works like lists and which works like numbers when considering variables assignment?