Augmented Assignement (was: Re: PEP scepticism)

Rainer Deyke root at rainerdeyke.com
Sun Jul 1 19:15:31 EDT 2001


"Courageous" <jkraska1 at san.rr.com> wrote in message
news:q0avjto87p59hn7gv28r5cf1c84j2fb8c7 at 4ax.com...
>
> >Correctness: Consider the following function:
> >
> >def f(x):
> >  x += (1, 2, 3)
> >  print x
>
> What do you think of:
>
> def f(x):
> x = x + (1,2,3)
> print x
>
> ?

A vast improvement: clear, unambiguous, and correct.  I can safely pass a
list as an argument and not have it modified behind my back.  Having to
write "x" twice on the second line is not good, but if it buys me
correctness, I'll happily pay that price.


--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games           -           http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor





More information about the Python-list mailing list