Clarification on Immutability please
On Wed, Jan 22, 2020 at 8:01 AM Jon Ribbens via Python-list
<python-list at python.org> wrote:
> On 2020-01-21, Chris Angelico <rosuav at gmail.com> wrote:
> > On Wed, Jan 22, 2020 at 4:42 AM Stephen Tucker <stephen_tucker at sil.org> wrote:
> >> I am left concluding that mytup is not actually a tuple (even though type
> >> (mytup) tells me that it is).
> > If type(mytup) is tuple, then mytup really truly is a tuple. There is
> > no other conclusion.
> >> My only explanation is that mytup is, actually, a pointer to a tuple; the
> >> pointer can't change, but the contents of that pointer (or the data to
> >> which the pointer points) can change.
> > Incorrect. Python simply doesn't have that concept.
> It's a bit weird that you took the bit where he realised exactly what
> is actually happening and replied "incorrect".
What do you mean? In what way is mytup a pointer to something that can
change? If you're looking at a mutable object like a list, then you
could say that the variable is a reference to something that can
change ("pointer" is misleading, as Python references don't have
C-style pointer semantics, but near enough); however, you can't
replace the object at a particular location with a completely
different object, you can only make changes that the object itself
supports. And since this is a tuple, there are no such changes.
So what he's seeing cannot possibly be as he describes. In what way
are you saying that this is "exactly what is actually happening"?