+ 1
Python non consistent Object-variable identity?
Look at the code what happens: https://code.sololearn.com/cu6OcuKbp5Oj/#py
3 Réponses
+ 1
Simply because your variable is a reference to a list, when you assign to another variable they both have the same reference, so both refer to the same object. With integers you actually have a value assigned, so you can give the same value to other variables but they are separate entities
edit: I'm not as familiar with how python deals with ints internally, perhaps this will help
https://www.laurentluce.com/posts/python-integer-objects-implementation/
+ 1
With integers the variable points to an integer value in memory, so the id changes whenever the value does, pointing to the new integer value. However other objects (lists included) keep pointing to the same object unless reassigned
0
Still the behaviour is different when variables point to integers as when they point to lists.