发布时间:2022-08-05 09:44:58 人气:182 作者:多测师
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培训之判断列表值是否为空,希望对大家有所帮助,如果想要了解更多Python相关知识,请关注多测师。https://www.e70w.com/xwzx/