• 技术文章 >常见问题 >Python常见问题

    如何判断python的列表不为空

    silencementsilencement2019-09-17 10:03:36原创7633

    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')
    专题推荐:list
    品易云
    上一篇:python3如何解决中文乱码 下一篇:后端php和python学哪个

    相关文章推荐

    • python如何打印列表长度• python中列表怎么删除元素• python如何创建列表

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网