判断python列表不为空的方法

  介绍

小编给大家分享一下判断python列表不为空的方法,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获、下面让我们一起去了解一下吧!

python中判断一个列表是否为空,可以使用以下方法

1,不是没有判断

列表不为空

list_1 =, []   if  list_1  is  not 没有:   ,,,print (& # 39; list  is  not 没有# 39;)

,列表为空

list_1 =, []   if  list_1 [0], is 没有:   ,,,print (& # 39; list_1  is 没有# 39;)

2。如果列表判断

列表不为空(空列表等于假)

list_2 =, []   if  list_2:   ,,,print (& # 39; list_2  is  not 没有# 39;)

3。长度列表长度判断

列表为空

list_3 =, []   if  len (list_3),==, 0:   ,,,print (& # 39; list_3  is 没有# 39;) list_3 =, []   if  len(列表):   ,,,print (& # 39; list_3  is  not 没有# 39;)

判断python列表不为空的方法