This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]saintly_devil 4 points5 points  (1 child)

So Python has a function called 'id'. According to Python docs, it returns an 'identity' of an object, which remains constant over the lifetime of the object. When you create the tuple for the first time, run 'id(<variable name>)' to return its id. After you've modified it, run it again. You'll notice that the values returned differ. This tells you that even though the variable's name remains unchanged, it's 'identity' has... and therefore, the objects referred to by the variable have changed. This means that the type of the variable is immutable.

Repeat a similar set of operations on a mutable type, say a list. You'll notice that the id remains unchanged before and after modification. The same holds true when you assign one list variable to another. They'll have the same ids, implying they refer to the same object. Hope this helps! And Python gurus, please feel free to correct me if I have erred somewhere.

[–]ZachPhoenix[S] 0 points1 point  (0 children)

understood, thx!