# Python | Check if tuple has any None value

• Last Updated : 26 Nov, 2019

Sometimes, while working with Python, we can have a problem in which we have a record and we need to check if it contains all valid values i.e has any None value. This kind of problem is common in data preprocessing steps. Let’s discuss certain ways in which this task can be performed.

Method #1 : Using any() + map() + lambda
Combination of above functions can be used to perform this task. In this, we check for any element using any() and extension of logic is done by map() and lambda.

 # Python3 code to demonstrate working of# Check if tuple has any None value# using any() + map() + lambda  # initialize tupletest_tup = (10, 4, 5, 6, None)  # printing original tupleprint("The original tuple : " + str(test_tup))  # Check if tuple has any None value# using any() + map() + lambdares = any(map(lambda ele: ele is None, test_tup))  # printing resultprint("Does tuple contain any None value ? : " + str(res))
Output :
The original tuple : (10, 4, 5, 6, None)
Does tuple contain any None value ? : True

Method #2 : Using not + all()
This checks for truthness of all elements of tuple using all() and with not, returns True if there is no None element.

 # Python3 code to demonstrate working of# Check if tuple has any None value# using not + all()  # initialize tupletest_tup = (10, 4, 5, 6, None)  # printing original tupleprint("The original tuple : " + str(test_tup))  # Check if tuple has any None value# using not + all()res = not all(test_tup)  # printing resultprint("Does tuple contain any None value ? : " + str(res))
Output :
The original tuple : (10, 4, 5, 6, None)
Does tuple contain any None value ? : True

My Personal Notes arrow_drop_up