Algorithm


# Step 1: Start

# Step 2: Initialize a variable `my_list` with the given list.
my_list = []  # Replace this with your list

# Step 3: Check if the length of `my_list` is equal to 0.
if len(my_list) == 0:

# Step 4: If the length is 0, print "The list is empty."
    print("The list is empty.")
else:

# Step 5: If the length is not 0, print "The list is not empty."
    print("The list is not empty.")

# Step 6: End

Code Examples

#1 Code Example- Using Boolean operation

Code - Python Programming

my_list = []
if not my_list:
    print("the list is empty")
Copy The Code & Try With Live Editor

Output

x
+
cmd
the list is empty

#2 Code Example- Using len()

Code - Python Programming

my_list = []
if not len(my_list):
    print("the list is empty")
Copy The Code & Try With Live Editor

Output

x
+
cmd
the list is empty

#3 Code Example- Comparing with []

Code - Python Programming

my_list = []
if my_list == []:
    print("The list is empty")
Copy The Code & Try With Live Editor

Output

x
+
cmd
The list is empty
Advertisements

Demonstration


Python Programing Example to Check If a List is Empty-DevsEnv