python 怎么判断不是个空列表
可以使用以下方法来判断一个列表是否为空:
- 使用if语句
my_list = []
if my_list:
print("列表不为空")
else:
print("列表为空")
- 使用len()函数
my_list = []
if len(my_list) != 0:
print("列表不为空")
else:
print("列表为空")
- 使用not关键字
my_list = []
if not my_list:
print("列表为空")
else:
print("列表不为空")
原文地址: https://www.cveoy.top/t/topic/eF0K 著作权归作者所有。请勿转载和采集!