首页 > 代码库 > python 清空列表

python 清空列表

方法:直接赋值为空list

对于一个一维list:

>>> a = [1,2,3]
>>> a = []
>>> a
[]

对于一个二维list:

>>> a = [[1,2,3,4,5],[6,7,8,9,10]]
>>> a = [[],[]]
>>> a
[[], []]

想清空二维list中的某一维;

>>> a = [[1,2,3,4,5],[6,7,8,9,10]]
>>> a[0] = []
>>> a
[[], [6, 7, 8, 9, 10]]

 

python 清空列表