Quantcast
Channel: identifying objects, why does the returned value from id(...) change? - Stack Overflow
Viewing all articles
Browse latest Browse all 9

Answer by A.Ajorian for identifying objects, why does the returned value from id(...) change?

$
0
0

The thing is that, each object(value) has a unique id in Python, e.g objects 'hello' and 'hi' have their own ids or 10 and 11 have 2 other different ids. The other thing is that each variable is just a label for a specific objecect(value. Now, when we say j=10, the id of the object 10 is assigned to the variable j. Then when you change the value of j (e.g j=j+1), j will refer to another object. In other words j will become label of another object. So the id for j varies when it's value changes.There is also Python's caching approach which help it to be more efficient.For example when you write j=10 and x=10 rather creating 2 separate objects it creates just one object 10 with 2 labels j and x.


Viewing all articles
Browse latest Browse all 9

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>