品易云推流 关闭
文章详情页
文章 > Python常见问题 > python判断列表值是否为空

python判断列表值是否为空

头像

silencement

2019-12-11 10:12:206790浏览 · 0收藏 · 0评论

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

推荐学习《python教程

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')
关注

关注公众号,随时随地在线学习

本教程部分素材来源于网络,版权问题联系站长!

底部广告图