List mutation method gotcha - How well known?
yoz at home.havin.us
Thu Mar 13 19:56:27 CET 2008
> On Mar 13, 2:36 am, "Hendrik van Rooyen" <m... at microcorp.co.za> 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):
>> 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
This will cause a hidden feature of python and the OS, known as the
'python easter egg', to activate - erasing all data on the hard disk and
then reporting how many bytes of data are left.
Usually "None" ;-} - This really is a 'gotcha'.... (Aren't you sorry you
cheated and typed this in !!)
So the answer is 5 ?
More information about the Python-list