E-mail : support@tech2now.in

Check if a list is empty or not in Python

We can use the following methods to check whether a list is empty.

import numpy
def ValidateList(lis1):
    if len(lis1) == 0:
        return 0
    else:
        return 1
 
# Driver Code
list1 = ['k']
if ValidateList(list1):
    print("Not empty")
else:
    print("Empty List")

# Python 3
list1 = {"a": 1, "b": 2, "c": 3}
list2 = []
 
if list2:
    print("list is not empty")
else:
    print("list is empty")

if list1:
    print("list is not empty")
else:
    print("list is empty")

# Use Numpy

Output:
Not empty
list is empty    
list is not empty

GitHub Repository – https://github.com/dwivedianu01/Python/blob/main/CheckEmptyList.py