如何检查数组是否为空?

这个问题在这里已经有了答案:

  • 如何检查列表是否为空? 25个答案

  • a作为numpy的数组,使用:

    if a.size:
       print('array is not empty')
    

    (在Python中,像[1,2,3]这样的对象称为列表,而不是数组)。


    在这个问题中没有提到numpy。 如果通过数组来表示列表,那么如果将列表视为布尔值,则它将在其中包含项目时返回True,如果为空则返回False。

    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/22491.html

    上一篇: How to check if array is not empty?

    下一篇: How to check if a list is empty in Python?