Appending to []

Chris Angelico rosuav at gmail.com
Fri Apr 20 16:26:04 EDT 2012


On Sat, Apr 21, 2012 at 6:17 AM, Rotwang <sg552 at hotmail.co.uk> wrote:
> In general there's no reason why
>
>>>> a.method(arguments)
>>>> print a
>
> will print the same thing as
>
>>>> print a.method(arguments)
>
> since a method doesn't assign the value it returns to the instance on which
> it is called; what it does to the instance and what it returns are two
> completely different things.

It wouldn't ever assign its return value to the instance, but it might
return self, which allows method chaining. Can be very handy, though I
don't know off-hand how common it is in Python.

ChrisA



More information about the Python-list mailing list