python确定list是否为空的方法-创新互联
创新互联www.cdcxhl.cn八线动态BGP香港云服务器提供商,新人活动买多久送多久,划算不套路!

小编给大家分享一下python确定list是否为空的方法,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!
Python判断list是否为空的方法:
通过len()
list_test = []
if len(list_test):
print('list_test 为非空list') # 存在值即为True
else:
print('list_test 为空list') # 不存在值即为FALSE直接通过 if+list 判断
list_test = []
if list_test:
print('list_test 为非空list') # 存在值即为True
else:
print('list_test 为空list') # 不存在值即为FALSE用 list == [ ] 也是可行的,不过会有Expression can be simplified提示
list_test = []
if list_test == []:
print('list_test 为非空list') # 存在值即为True
else:
print('list_test 为空list') # 不存在值即为FALSE看完了这篇文章,相信你对python确定list是否为空的方法有了一定的了解,想了解更多相关知识,欢迎关注创新互联-成都网站建设公司行业资讯频道,感谢各位的阅读!
名称栏目:python确定list是否为空的方法-创新互联
网站网址:http://www.jxjierui.cn/article/dhidoj.html


咨询
建站咨询
