Python Program to Check List is Empty or Not

Write a Python Program to Check whether the List is Empty or Not. There are three possible ways to check the list empty: using the built-in len() function, not operator, and direct comparison of [] within the if statement.

Using not Operator

We use the not operator to find the list is an empty list. 

list1 = []

if not list1:
    print("The List is Empty")
else:
    print("The List is Not Empty")
Program to Check List Is Empty or Not

Python Program to Check List is Empty or Not using len

We used the Python list length function in this Python example that returns the list length. If the list length equals zero, then it’s an empty list; Otherwise, the list is not empty.

list1 = []

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

Direct Comparision to check list is empty

Apart from the approaches mentioned above, you can directly compare the list with [] to find whether the list is empty.

ls = []

if ls == []:
    print("True")
else:
    print("False")
True

In the program below, we evaluate a list directly in the if-else statement. By default, this programming language considers empty lists as false, so it returns false. Refer to Python if else.

ls = []
if ls:
print("List is not empty")
else:
print("List is empty")
List is empty

Also Read