List mutation method gotcha - How well known?
Roel Schroeven
rschroev_nospam_ml at fastmail.fm
Thu Mar 13 06:46:57 EDT 2008
Hendrik van Rooyen schreef:
> 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):
>
> 1) [1,2,3,4]
> 2) [1,2,3,4,5]
> 3) That famous picture of Albert Einstein sticking out his tongue
> 4) Nothing - no output
> 5) None of the above
Answer 5: the output will be 'None': append() doesn't return the list,
it returns None.
--
The saddest aspect of life right now is that science gathers knowledge
faster than society gathers wisdom.
-- Isaac Asimov
Roel Schroeven
More information about the Python-list
mailing list