Write a Python Program to Check If a List is Empty

Python Program to Check If a List is Empty

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn  Python programming concepts. You can learn Python language at your own speed and time. One can learn concepts of Python language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Python Program to Check If a List is Empty
Python Program to Check If a List is Empty

Write a Python Program to Check If a List is Empty

PROGRAM: Python Program to Check If a List is Empty

/* Python Program to Check If a List is Empty */

1: Using Boolean operation

my_list = []
if not my_list:
print(“the list is empty”)

Output

the list is empty

2: Using len()

my_list = []
if not len(my_list):
print(“the list is empty”)

Output

the list is empty

3: Comparing with []

my_list = []
if my_list == []:
print(“The list is empty”)
Output
The list is empty

Leave a Reply

Your email address will not be published. Required fields are marked *