教你一招判断Python-列表是否为空,很关键必须要学好

其他表对比判断
列表不为空:
list_1 = [1,2]list_2 = []if list_1 != list_2: print('list is not none') 列表为空:
list_1 = []list_2 = []
if list_1==list_2:
print('list_1 is none')
2.if 列表判断
列表不为空(空列表等于 False)
list_2 = [1,2]
if list_2:
print('list_2 is not none')
列表为空:
list_2 = []
if not list_2:
print('list_2 is none')
3.length列表长度判断
列表为空:
list_3 = []
if len(list_3) == 0:
print('list_3 is none')
列表不为空:
list_3 = [1,2]
if len(list_3):
print('list_3 is not none')