寫一個 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
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/246989.html