Site icon Machine Learning Projects

Python Program to Check If a List is Empty – 2023

Machine Learning Projects

Hey guys, in this blog we will see a Python Program to Check If a List is Empty.

Example 1: Using the Boolean operation

# Python Program to Check If a List is Empty 

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

Output

The list is empty

Example 2: Using len()

# Python Program to Check If a List is Empty 

my_list = []
if not len(my_list):
    print("The list is empty")

Output

The list is empty

Example 3: Comparing with []

# Python Program to Check If a List is Empty 

my_list = []
if my_list == []:
    print("The list is empty")

Output

The list is empty

Here we will simply compare our list with [] and if it is True, it means our list is empty and print ‘The list is empty’.

Check out our other python programming examples

Exit mobile version