We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

Check if Any Element in List is None in Python

This tutorial will discuss about a unique way to check if any element in list is none in Python.

To check if a List contains any None value, we can iterate over all the list elements, and for each element we can check if it is None or not.

We can do that using the any() method. In this method, we will iterate over all elements of list, using a for loop and evaluate if any element is None or not. It will result in a boolean sequence of True and False values. A True value denotes that corresponding value is None in the List.

Advertisements

The any() method will return True, if any element from the list satisfies the condition i.e. if any element is None in the List.

Let’s see the complete example,

listObj = [1, None, "Magic", True, 12, 89.0]

# Check if List contains any None Value
if any(elem is None for elem in listObj):
    print("Yes, List contains at least a None value")
else:
    print("No, List does not have any None value")

Output

Yes, List contains at least a None value

Summary

We learned a way to check if List contains any None value in Python.

Cart

Your Cart is Empty

Back To Shop