如何判断python的列表不为空

761次阅读
没有评论

如何判断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')
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:wuyou2019-10-15发表,共计428字。
新手QQ群:570568346,欢迎进群讨论 Python51学习
评论(没有评论)