Augmented Assignement (was: Re: PEP scepticism)

Guido van Rossum guido at python.org
Fri Jul 6 07:34:04 EDT 2001


"Rainer Deyke" <root at rainerdeyke.com> writes:

> Correctness: Consider the following function:
> 
> def f(x):
>   x += (1, 2, 3)
>   print x
> 
> This function is just plain incorrect.

Depends on context.  If you write a small program that by convention
manipulates tuples, this would be totally acceptable.

Not every function needs to be written polymorphically to work on all
kinds of arguments.  Many functions are by convention only used on
specific argument types, and both the caller and the function author
know that.  Then using the += notation on an argument is totally
acceptable.  The statement that f is *incorrect* is meaningless
without context.

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-list mailing list