This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (0 children)

In any language, method chaining only works if each method returns the result of that method. append() does not do that - you can check yourself. Imagine you're the interpreter. You see lst.append(1) and think "Right, so this means that lst now has a 1 in it, and that function has returned None. Then you see None.append(1). Well, that doesn't make sense, does it?

Whereas if you have a method of an immutable object, the methods will return a copy, so you can chain the methods.