How to check if a list is empty in Python?
This question already has an answer here:
if not myList:
print "Nothing here"
在布尔上下文if some_list:
列表的计算结果为False(比如if some_list:
。
I like Zarembisty's answer. Although, if you want to be more explicit, you can always do:
if len(my_list) == 0:
print "my_list is empty"
链接地址: http://www.djcxy.com/p/22490.html
上一篇: 如何检查数组是否为空?
下一篇: 如何检查Python中的列表是否为空?