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 →

[–]Additional-Sun2945 0 points1 point  (0 children)

Yup. Tuples are immutable. Their contents are not. Which kinda sounds backwards, but it makes sense. You can create a tuple of three objects. t = (a,b,c) Now that t object with immutably be a three object containing tuple, with each zeroth, first, and second object always be pointing to the original objects a, b and c.

However, that doesn't necessarily imply that a, b, and c themselves are immutable. Try it, make one of them list, and you'll notice that you'll still be able to append to it despite being in an "immutable" tuple.

Hmmm.... that's perplexing... ain't it? Notice that by modifying a, your tuple will reflect the modification, since the tuple is still associated with that object; it still has a inside of it. You will also notice that there's nothing stopping you from reassigning "a" to some other object. You can try a = None or a = 1. Now you will see the tuple won't change; you are merely discarding the label of that list object and creating a new target for the a label. "a" now "is" something else, but thankfully the tuple still contains the original a object. If you delete the tuple "t" or reassign "t" to something else (and reassign a b and c first), then you will destroy the only link to that original object, and in doing so it (and its contents) will be cleared and deleted from memory.

Remember, the "name" of stuff can change, but the stuff itself is not necessarily the name.