您现在的位置是:课程教程文章

如何判断python的列表不为空

2023-12-18 22:33课程教程文章 人已围观

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

1、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')

2.if 列表判断

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

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

3.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的列表不为空

上一篇:linux中如何使用python

下一篇:没有了

站点信息

  • 文章统计篇文章