How to delete a Python list without a list = []?

If the variable my_listis global, you cannot:

my_list = []

which simply create a new link in the local area.

Also, I found it disgusting to use a keyword global, so how can I clear a list using its methods?

+3
source share
2 answers
del a[:]

or

a[:] = []
+11
source

How to remove the following list items:

def emptyit():
    del l[:]
+1
source

Source: https://habr.com/ru/post/1762494/


All Articles