append method

Emile van Sebille emile at fenx.com
Wed May 23 15:13:19 EDT 2012


On 5/23/2012 5:23 AM 水静流深 said...
>  >>> s=[1,2,3]
>  >>> s.append(5)
>  >>> s
> [1, 2, 3, 5]
>  >>> s=s.append(5)
>  >>> s
>  >>> print s
> None
>
> why can't s=s.append(5)

It could, but it doesn't.


> ,what is the reason?


A design decision -- there's currently a mix of methods that return 
themselves and not.  Mostly is appears to me that mutables modify in 
place without returning self and immutables return the new value.

But that's simply my observation.

Emile





More information about the Python-list mailing list