List mutation method gotcha - How well known?

Peter Otten __peter__ at web.de
Thu Mar 13 05:20:15 EDT 2008


Hendrik van Rooyen wrote:

> I am surprised that it took me so long to bloody my nose on this one.
> 
> It must be well known - and I would like to find out how well known.
> 
> So here is a CLOSED BOOK multiple choice question - no RTFM,
> no playing at the interactive prompt:
> 
> Given the following three lines of code at the interactive prompt:
> 
> foo = [1,2,3,4]
> x = foo.append(5)
> print x
> 
> What will be the output (choose one):

I thought it were a FAQ, but found only

http://effbot.org/pyfaq/why-doesn-t-list-sort-return-the-sorted-list.htm

I'm sure you can draw the analogy.

Peter



More information about the Python-list mailing list