ITPub博客

首页 > IT职业 > IT图书 > python判断列表值是否为空

python判断列表值是否为空

IT图书 作者:fff2001 时间:2021-09-11 10:25:49 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')

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/3664/viewspace-2835232/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-08-14

  • 博文量
    74
  • 访问量
    657