导语:
本文主要介绍了关于如何判断python的列表不为空的相关知识,包括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使用冒号09/05
- ♥ 如何从python中的数组中删除指定元素10/03
- ♥ 如何在 python 中使用 scipy.fftpack 模块计算快速傅里叶变换?10/16
- ♥ 在 Python 中给我一面旗帜12/01
- ♥ 如何在python中分解素数?08/19
- ♥ 小白学习Python时最常犯的6个错误11/15
内容反馈