Augmented Assignement (was: Re: PEP scepticism)

Paul Prescod paulp at ActiveState.com
Fri Jun 29 15:17:59 EDT 2001


Mark 'Kamikaze' Hughes wrote:
> 
>...
>   What would you expect from "mytuple = mytuple + (foo,bar)", and why
> would this be different from "mytuple += (foo,bar)"?

Different people expect different things. Based on my knowledge of C I
would expect that mytuple += would rebind.

>...
> 
>   What would you expect from "mylist = mylist + [foo, bar]", and why
> would this be different from "mylist += [foo, bar]"?

It is different right now:

>>> mylist = yourlist = [5]
>>> mylist = mylist + [3,4]
>>> mylist
[5, 3, 4]
>>> yourlist
[5]

>>> mylist = yourlist = [5]
>>> mylist += [3,4]
>>> mylist
[5, 3, 4]
>>> yourlist
[5, 3, 4]

Naive users do not expect the operator's relationship to the *namespace*
to depend on the type of the operands.

-- 
Take a recipe. Leave a recipe.  
Python Cookbook!  http://www.ActiveState.com/pythoncookbook




More information about the Python-list mailing list