导语:
本文主要介绍了关于如何判断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')
列表不为空(空列表等于 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中__file__属性的使用01/05
- ♥ Python高级特性:容易被忽视的不可变类型12/27
- ♥ 如何在python中注释代码10/02
- ♥ python如何遍历元组10/19
- ♥ python中的匿名函数是什么?09/22
- ♥ Python 解析器如何搜索模块位置10/31
内容反馈