0

Datatype set with id() function, why do we see different address for name and value?

Hello Python Community, I am trying to understand mutable and immutable characteristics of python datatypes. After reading some articles I developed an understanding and wanted to test my understanding using variable and heap view in Thonny. Please go to line 79 to 84 of my code and help me with my problem https://code.sololearn.com/cgaVDzTS02sM/#py Because list, dictionary are mutable. I am should see different addresses if I run id() function for both the name (identifier aka variable) and value (data, here a list or dictionary). This works. I am happy. Because tuple is immutable, I should see same address if I I run id() function for both the name (identifier aka variable) and value (data, here a tuple). This works. I am happy. Just for set, which we know is a immutable datatype, if I run id() function for both the name (identifier aka variable) and value (data, here a set) I get different addresses. Why? I am confused.

23rd Jul 2020, 11:07 PM
Expensive Harmonica
Expensive Harmonica - avatar
2 Réponses
0
I think I mixed up immutable and unordered features. My question was wrong. Set is in fact a mutable datatype in python hence the id() function will infact provide different memory address for value and name. Topic : CLOSED
24th Jul 2020, 9:59 PM
Expensive Harmonica
Expensive Harmonica - avatar
0
The `set` object defined at line 81 is a reference object, an object represented by an identifier <a>. We can refer to that object by the identifier later on. The `set` object at line 83 is a temporary object Python created for the id() function interest solely. The temporary object is immediately destroyed as it no longer be needed (read: after the object's unique ID is printed)
25th Jul 2020, 9:27 AM
Ipang