How to empty a Python list without doing list = []?
If the my_list
variable is global, you can't do:
my_list = []
that just create a new reference in the local scope.
Also, I found disgusting using the global
keyword, so how can I empty a list using its开发者_JS百科 methods?
del a[:]
or
a[:] = []
How about the following to delete all list items:
def emptyit():
del l[:]
精彩评论