判断python列表不为空的方法

小编给大家分享一下判断python列表不为空的方法,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

创新互联主要企业基础官网建设,电商平台建设,移动手机平台,微信小程序等一系列专为中小企业定制网站产品体系;应对中小企业在互联网运营的各种问题,为中小企业在互联网的运营中保驾护航。

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列表不为空的方法
网站地址:http://pwwzsj.com/article/jcgseg.html