Check if the list is empty in python

There are several ways to check if the list is empty or not in python. I frequently use the if statement either with not operator or without. Here is an example.

# An empty list
list_A = []

if not list_A:
    print("List list_A is empty\n")

# Now fill the list
list_A = ["a", "b", 1, 2, "e", "f"]

if list_A:
    print("List list_A:", list_A)
check if the list is empty in Python

Reference


Leave your thoughts...

This site uses Akismet to reduce spam. Learn how your comment data is processed.