python如何判断列表是否为空

这篇文章运用简单易懂的例子给大家介绍python如何判断列表是否为空,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

is not None 判断

列表不为空

list_1 = []
if list_1 is not None:
    print('list is not none')

列表为空

list_1 = []
if list_1[0] is None:
    print('list_1 is none')

if 列表判断

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

list_2 = []
if list_2:
    print('list_2 is not none')

length列表长度判断

列表为空

list_3 = []
if len(list_3) == 0:
    print('list_3 is none')
list_3 = []
if len(list):
    print('list_3 is not none')

关于python如何判断列表是否为空就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。