Why is there no list.clear() method in python?

In the threads you linked Raymond Hettinger pretty much sums up the pros and cons of adding that method. When it comes to language design, it's really important to be conservative. See for example the "every feature starts with -100 points" principle the C# team has. You don't get something as clean as Python by adding features willy-nilly. Just take a look at some of the more cruftier popular scripting languages to see where it takes you.

I guess the .clear() method just never did cross the implicit -100 points rule to become something worth adding to the core language. Although given that the methodname is already used for an equivalent purpose and the alternative can be hard to find, it probably isn't all that far from it.


While there was no list.clear() when this question was asked, 3.3 now has one (as requested in http://bugs.python.org/issue10516). Additionally, clear() methods have been added to bytearray and MutableSequence to ease switching between lists and other collections (set, dict etc).

Full details of the change can be found here.

Tags:

Python

List