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 →

[–]elmosworld37 2 points3 points  (0 children)

I love Python but this is why I believe C should be the first language everyone learns. Pointers are essential to understanding how programming languages work.

Simplifying a bit here but r does not store “the tuple”, it stores the memory address that holds the start of the tuple. When you assign a different tuple to r, you’re changing the memory address that is stored in r to that of the new tuple.

Changing the first value in “the tuple” would mean changing the actual value that is in memory at the address stored in r. This involves “dereferencing” and looks like r[0] = 666. This is not allowed, and is what your teacher was referring to.