To check if any item in a list is None in python, we can use the membership Operators or list comprehension.
Check if any item in a list is None using Python
In Python, ‘None’ is a specific object indicating that the object is missing the presence of a value. The Python Null object is the singleton None.
Note: constant ‘None’ is defined as False, so when combined using the same logical operator or always returns False.
To check if any item in a list is None, we have the following ways:
Use the membership Operators
The membership operators in Python include ‘in’ and ‘not in’.
The ‘in’ operator will return True if the specified argument occurs in a set and vice versa.
The ‘not in’ operator will return True if the specified argument is not in the set and vice versa.
Example:
- Initializes a list of both strings and None.
- Use the membership operator to check if the value None appears in the list.
# A list consisting of strings and None myList = ["Learn", None, "Share", None, None, "IT"] # Use the in operator to check if any item in a list is None if None in myList: print('The list contains the value None') else: print('The list does not contain the value None')
Output:
The list contains the value None
Or you can use the ‘not in’ operator to check.
Example:
# A list consisting of strings and None myList = ["Learn", None, "Share", None, None, "IT"] # Use the in operator to check if any item in a list is None if None not in myList: print('The list does not contain the value None') else: print('The list contains the value None')
Output:
The list contains the value None
The program still outputs that command line because there is a None value in the list.
Use list comprehension
Example:
- Initializes a list of both strings and None.
- Use the list comprehension to output the None values contained in the list.
# A list consisting of strings and None myList = ["Learn", None, "Share", None, None, "IT"] # Use list comprehension to output None values in the list result = [x for x in myList if x is None] print('The value None appears in the list:', result)
Output:
The value None appears in the list: [None, None, None]
Use the any() function
Syntax:
any(iterable)
Parameters:
- iterable: Can be a list, string, dictionary,… in Python.
The any() function returns:
- True if at least one element in an iterable is True.
- False if all elements in iterable are False or iterable is empty.
Example:
- Initialize a list of both strings and None.
- Use the any() function to check if the value None appears in the list.
# A list consisting of strings and None myList = ["Learn", None, "Share", None, None, "IT"] # Use the any() function to output None values in the list result = any(x is None for x in myList) print('The value None appears in the list:', result)
Output:
The value None appears in the list: True
Summary
Above are some ways I often use to check if any item in a list is None using Python. After reading this article, you may have better ways for this topic.
Maybe you are interested:
- Remove \r\n from a string or list of strings in Python
- Remove an element from a list by index in python
- Convert a list of characters into a string in Python

My name is Jason Wilson, you can call me Jason. My major is information technology, and I am proficient in C++, Python, and Java. I hope my writings are useful to you while you study programming languages.
Name of the university: HHAU
Major: IT
Programming Languages: C++, Python, Java