Here are seven ways to check if a list is empty in Python.
- Using not in operator
- Using len() method
- By comparing with an empty list
- Check the empty list using the PEP 8 recommended method
- Comparing a given list with an empty list using != operator
- Using list comprehension + len()
- Using NumPy module
Method 1: Using the not in operator
To check if a list is empty in Python, you can use the not operator with the if condition. The not operator checks the existence of a specified value inside a given sequence, but it returns a value opposite to that of the in operator.
listA = []
if not listA:
print('List is empty')
else:
print('List is not empty')
Output
List is empty
Method 2: Using the len() Function
The len() function is used to find the number of elements in the list. To check if the list is empty using len(), pass the empty list to the len() function, and if we get 0, that means the list is empty.
listA = []
if not len(listA):
print('List is empty')
else:
print('List not empty')
Output
List is empty
We can also use the double equal to compare with 0 to check if the list is empty.
listA = []
if len(listA) == 0:
print('List is empty')
else:
print('List not empty')
Output
List is empty
Method 3: Compare the empty list with another empty list.
Compare our current list to [ ]; we will get an idea if the list is empty.
listA = []
if listA == []:
print('List is empty')
else:
print('List not empty')
Output
List is empty
Method 4: Checking an empty list using the PEP 8 recommended method
The PeP8 allows us to determine whether a list in Python is empty.
list1 = {"A": 1, "B": 2, "C": 3}
list2 = []
if list2:
print("list is not empty")
else:
print("list is empty")
Output
list is empty
Method 5: Comparing a given list with an empty list using != operator
import numpy as np
list2 = []
if list2 != []:
print("The list is not empty")
else:
print("Empty List")
Output
Empty List
Method 6: Using list comprehension + len()
Output
['not empty']
Method 7: numpy module
import numpy as np
list2 = []
result_array = np.array(list2)
if result_array.size == 0:
print('Empty list')
else:
print('List is not Empty')
Output
Empty list
That’s it.

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.