Method chaining

Terry Reedy tjreedy at udel.edu
Fri Nov 22 07:34:53 EST 2013


On 11/22/2013 6:26 AM, Steven D'Aprano wrote:
> A frequently missed feature is the ability to chain method calls:
>
> x = []
> x.append(1).append(2).append(3).reverse().append(4)
> => x now equals [3, 2, 1, 4]
>
>
> This doesn't work with lists, as the methods return None

True for the 7 pure mutation methods but not for .copy, .count, .index, 
and .pop. The last both mutates and returns.

-- 
Terry Jan Reedy




More information about the Python-list mailing list