Python3 AttributeError: 'list' object has no attribute 'clear'

前端 未结 1 821
走了就别回头了
走了就别回头了 2020-12-31 04:21

I am working on a Linux machine with Python version 3.2.3. Whenever I try to do list.clear() I get an exception

>>> l = [1, 2, 3, 4,          


        
相关标签:
1条回答
  • 2020-12-31 04:56

    list.clear was added in Python 3.3.

    Citing the Mutable Sequence Types section in the documentation:

    New in version 3.3: clear() and copy() methods.

    s.clear() removes all items from s (same as del 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[:] = [].

    0 讨论(0)
提交回复
热议问题