Can Python function return multiple data?

BartC bc at freeuk.com
Fri Jun 5 06:06:50 EDT 2015


On 05/06/2015 02:48, Steven D'Aprano wrote:
> On Fri, 5 Jun 2015 11:40 am, Mark Lawrence wrote:
>
>> On 05/06/2015 01:16, BartC wrote:
>>> On 05/06/2015 00:13, Steven D'Aprano wrote:
>>>> On Fri, 5 Jun 2015 06:52 am, BartC wrote:
>>>>
>>>>> On 04/06/2015 18:11, Steven D'Aprano wrote:
>>>>>
>>>>>> If there is
>>>>>> any language where assignment uses one style and argument passing
>>>>>> always
>>>>>> uses another, I've never come across it.
>>>>>
>>>>> My language does that. I'd be very surprised if it was the only one in
>>>>> existence that does so.
>
> [...]
>
>> Really?
>
> Probably. I can't be sure, because I've never used Bart's language. But
> surely he has no reason to lie about his language, and I'm pretty sure you
> can't disprove any claims about his language by running Python code.

Well, my language does assignments differently.

Using tmp=x[:], the Python example will emulate the behaviour better.

(This is actually what I've always had trouble getting my head around. 
For example:

x=[10,20]
y=[x,x,x]
print (y)

gives:

   [[10,20],[10,20],[10,20]]

So far so good. But now, thousands of lines and minutes of runtime later 
so that everyone's forgotten that exactly y was from x:

  x[0]="Cat"
  print (y)

gives:

    [['Cat',20],['Cat',20],['Cat',20]]

WTF?!

Or:

   y[0][0]=99      # change one element, you think
   print (y)

=> [[99,20],[99,20],[99,20]]      # no, you change half of them!

Anyway, I am now upgrading my language to work the same way, *and* 
getting rid of explicit pointers, references and full pass-by-reference, 
because Python seems to manage without them. I'll find out in few weeks 
if I've made a big mistake!)

-- 
Bartc



More information about the Python-list mailing list