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

前端 未结 4 1318
长情又很酷
长情又很酷 2021-01-01 08:38

Inspired by this question.

Why is there no list.clear() method in python? I\'ve found several questions here that say the correct way to do it is one of the followin

4条回答
  •  萌比男神i
    2021-01-01 09:19

    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.

提交回复
热议问题