Example:
tuple = ("python", "includehelp", 43, 54.23)
Checking For None Values in Python
In this program, we are given a tuple consisting of some values. And we will be creating a Python program that will check whether the given Tuple is a None tuple or not.
None Tuple is a tuple whose all values are none.
Example:
(None, None, None)
To check for None Tuple we need to traverse the tuple and check if each value is a None value or not. If all values are none, return true otherwise false.
This can be performed in Python using multiple method combinations. Let's see some of them here.
Method 1:
One method to check for none tuple is to check if all elements are None by using the all() method with a generator expression.
Output:
Method 2:
One more method to check if the tuple is a none tuple or not is by comparing the number of none values in the tuple which is the length of the tuple. If both are the same then the tuple is none tuple otherwise not.
The length of the tuple is calculated using len() method and the count of none elements is found using the count() method.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer