Can Python function return multiple data?

Chris Angelico rosuav at gmail.com
Fri Jun 5 23:49:44 EDT 2015


On Sat, Jun 6, 2015 at 1:28 PM,  <random832 at fastmail.us> wrote:
> On Fri, Jun 5, 2015, at 23:20, Rustom Mody wrote:
>> The word immutuable happens to have existed in English before python.
>> I also happen to have used it before I knew of python
>> The two meanings do not match
>> I am surprised
>> Is that surprising?
>
> They don't match only if you consider the objects a tuple references to
> be part of the tuple.
>
> You cannot change the reference. It will always point to the same list.

Precisely. I can use indelible ink to write a phone number on a piece
of paper, but that's no guarantee that the same person will always
answer that phone. Doesn't change the indelibility of the writing. If
you want something truly immutable, you have to be careful to
reference only other immutables. In Python, hashability is pretty much
that, but I don't think English has such a concept.

Even if there is a word in English with a slightly different meaning
from its Python meaning, is that so hard to believe? In common usage,
a "dictionary" is something which maps words to their meanings, is
ordered ("dictionary order" being a variant of alphabetical order
which takes into account non-alphabetic characters, diacriticals,
etc), and may have additional information that isn't strictly part of
the mapping. In Python, a "dictionary" is something which maps
hashable values to objects. That's pretty different, but clearly
connected. In many languages, "integer" actually means "integer less
than X" (eg X = 2**32), but people don't complain that that means
they're not integers.

In Python, immutables can contain references to mutables, and the
perceived behaviour of a tuple may be affected by those objects.
They're still immutable.

ChrisA



More information about the Python-list mailing list