开发者

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[:]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜