How do I check if a list is empty in Python?

Better Stack Team
Updated on January 26, 2023

You can check if a list is empty by using the len() function to check the length of the list. If the length of the list is 0, then it is empty.

Here's an example:

 
my_list = []

if len(my_list) == 0:
    print("The list is empty")
else:
    print("The list is not empty")

You can also use the following concise syntax to check if a list is empty:

 
if not my_list:
    print("The list is empty")
else:
    print("The list is not empty")

Both of these methods will work to check if a list is empty.