How to check if array is not empty?
This question already has an answer here:
with a
as a numpy array, use:
if a.size:
print('array is not empty')
(in Python, objects like [1,2,3]
are called lists, not arrays.)
There's no mention of numpy in the question. If by array you mean list, then if you treat a list as a boolean it will yield True if it has items and False if it's empty.
l = []
if l:
print "list has items"
if not l:
print "list is empty"
if self.table:
print 'It is not empty'
也没关系
链接地址: http://www.djcxy.com/p/22492.html上一篇: 表达式可以在布尔文字上简化
下一篇: 如何检查数组是否为空?