Why doesn't this work?

Hans Nowak wurmy at earthlink.net
Thu Dec 6 23:16:52 EST 2001


Courageous wrote:
> 
> Python 2.2b2 (#26, Nov 16 2001, 11:44:11) [MSC 32 bit (Intel)] on
> win32
> Type "copyright", "credits" or "license" for more information.
> IDLE 0.8 -- press F1 for help
> >>> def f(): return [1,2,3]
> 
> >>> f()
> [1, 2, 3]
> >>> f().append(4)
> >>> l=f().append(4)
> >>> l
> >>>
> 
> Obviously I can fix this, but I'm wondering why it doesn't work
> the way I expected it to?

Because append() doesn't return a value... it changes the list
in place. (Well, actually, it returns None.)

--Hans



More information about the Python-list mailing list