Emma Pascoe
Emma Pascoe

Reputation: 157

Python: Memory Model ID

Does the order in which you enter things into Python affect the ID of that object? (ie. if I first type s = list1, then s2 = list2, will the ID of s be 1 and the ID of s2 be 2?)

Upvotes: 0

Views: 53

Answers (1)

rje
rje

Reputation: 6438

The id of an object is its memory location. There is no guarantee about where in memory something will be stored, or whether a newer object will stored at a "higher" address.

For example, let's say we make an object a, then b. Then we remove and garbage collect a and make a new object c. This new object c might just be stored in a's old location. Or not. There is no real way of knowing. It's all handled by the python memory manager which does things in such a way that the user cannot really know where a new object will end up.

So in general, the answer to your question is "no".

For more info see the following post: What is the id( ) function used for?

Upvotes: 1

Related Questions