Can Python function return multiple data?

random832 at fastmail.us random832 at fastmail.us
Thu Jun 4 13:51:49 EDT 2015


On Thu, Jun 4, 2015, at 13:36, Michael Torrie wrote:
> Surely two objects can hold the same value, or represent the same value
> (number), without *having* to be the same object.  I don't see why
> people would assume, let alone demand that different objects
> representing the same value be the same actual object.  Why should it
> even matter? Just relax and write code.  I enjoy the forays into the the
> technical, and even the pedantic, but this is getting a bit silly.

I think I've solved the terminology problem...

it's call-by-value, but the value of a variable, or an argument, or an
expression, is not the value of the object, but rather it is the object
(or, if you like, the id of the object.)

So it's call-by-value where the object is the value that is _really_
passed in. "The value of an object" is simply an equivalence
relationship (so, the value of [1, 2] is the same as the value of [1, 2]
until one of them changes) defined by the hash and == operators of the
object's class rather than having any meaning to the language.

Imagine you have a, b = [1, 2], [1, 2]. If a and b had the same value,
then you could substitute them - a[0] = 3 would have the same effect as
b[0] = 3.

Immutable objects confuse this, because there aren't any operations you
can do to one that would cause its value to be different from another
one that once had the same value, so people think the value of the
variable is the value of the object rather than the value of the
variable being *the object*.



More information about the Python-list mailing list