欢迎光临
我们一直在努力

Python 程序:检查列表是否为空

九八云Python教程:

写一个 Python 程序来检查列表是否为空。我们用 Python not 运算符发现列表是一个空列表。

# List is Empty

list1 = []

if not list1:
    print("The List is Empty")
else:
    print("The List is Not Empty")

在这个 Python 示例中,我们使用了返回列表长度的 len 函数。如果列表长度等于零,那么它就是一个空列表;否则,列表不为空。

# List is Empty

list1 = []

if len(list1) == 0:
    print("The List is Empty")
else:
    print("The List is Not Empty")
The List is Empty

赞(0) 打赏
未经允许不得转载:九八云安全 » Python 程序:检查列表是否为空

评论 抢沙发