Checking if list is empty
suggest changeAn empty list is falsy (bool([]) is False, but [] == False is not true), so you can test if not lst instead of if len(lst) == 0.
lst = []
if not lst:
print("list is empty")
# Output: list is empty
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents