开发者社区 问答 正文

python判断列表值是否为空

python判断列表值是否为空

展开
收起
保持可爱mmm 2019-12-11 15:05:41 486 分享 版权
1 条回答
写回答
取消 提交回答
  • 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')
    

    免费视频教程

    2019-12-11 15:05:53
    赞同 展开评论
问答分类:
问答地址: