檢查列表是否為空

列表的空白與布林 False 相關聯,因此你不必檢查 len(lst) == 0,而只需檢查 lst 或 not lst

lst = []
if not lst:
    print("list is empty")

# Output: list is empty