Can Python function return multiple data?

Rustom Mody rustompmody at gmail.com
Fri Jun 5 09:29:10 EDT 2015


On Friday, June 5, 2015 at 4:36:35 PM UTC+5:30, Steven D'Aprano wrote:
> On Fri, 5 Jun 2015 01:16 pm, Rustom Mody wrote:
> > The abstract platonic immutable list is non-existent in python
> 
> Just pretend that "immutable list" is spelled "tuple".

Ok lets say I make no fuss about the need to 'pretend'.

And I try...

>>> a=[1,2,3]
>>> b=(a,a)
>>> a
[1, 2, 3]
>>> b
([1, 2, 3], [1, 2, 3])
>>> a.append(4)
>>> b
([1, 2, 3, 4], [1, 2, 3, 4])

> 
> 
> > Use no mutation and the pretence that the list [1,2] *is* the list [1,2]
> > works.
> > 
> > Start using mutation and the ground starts wobbling.
> 
> Mutation is irrelevant here. Some objects are immutable, others are mutable,
> but the language semantics are the same for both.
> 
> In particular, Python provides as a language feature two ways to compare
> objects for identity. Python makes no promises as to when it will re-use
> immutable objects, but it does promise that you can always test for re-use
> by using `is` or `id()`. So there's no "wobbly ground" here. You can
> *always* tell if (supposedly) two objects are in fact the same object or
> not, since `is` cannot be shadowed or monkey-patched.
> 
> 
> > The only way to stay steady (that I know) in this wobbly world is to hold
> > to two concepts:
> > 1. The abstract platonic immutable type -- good to think with, supported
> > by python in only a half-assed way
> > 
> > 2. The 'maybe-reference-maybe-value' actual mess
> > 
> > And to keep dancing between these
> 
> All the words are in English, but I have no idea what you are trying to say
> here.

It was an analogy.
C programmers use lists all right all the time.
However until they see something like python, they dont know that they never
REALLY saw lists. ie lists in python are more first-class than C.

Analogously immutable lists are more first-class than python lists.

Of course the language (we are conversing in) is itself very misleading.
We dont call a number an 'immutable' number. In
x = 3
x = x - 1
it is x that changes, not 3.

Whatever would/could it mean that 3 becomes 2?

If 3 becomes 2 does π become 2.142? Do circles look different?
Does the normal curve (with a π in the denominator) start wiggling?

What I am driving at is that immutable numbers are so deeply enshrined in our
culture that anything else is inconceivable.

Yet for lists one needs to spell out
immutable → tuple
mutable → list
This means that in our culture lists have not reached the first-class status 
that numbers have.  Python is just following the culture



More information about the Python-list mailing list