Python3 AttributeError: 'list' object has no attribute 'clear'
list.clear
was added in Python 3.3.
Citing the Mutable Sequence Types section in the documentation:
New in version 3.3:
clear()
andcopy()
methods.
s.clear()
removes all items froms
(same asdel s[:]
)
See the issue #10516 for the relevant discussion and alternative ways of clearing lists. In summary, it is the same as del l[:]
and l[:] = []
.