- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check if tuple has any None value in Python
When it is required to check if a tuple has any 'None' value or not, the 'any' method, the 'map' method and the lambda function can be used.
The map function applies a given function/operation to every item in an iterable (such as list, tuple). It returns a list as the result.
Anonymous function is a function which is defined without a name.
In general, functions in Python are defined using 'def' keyword, but anonymous function is defined with the help of 'lambda' keyword. It takes a single expression, but can take any number of arguments. It uses the expression and returns the result of it.
The 'any' method checks to see the iterable if at least one True value exist. If yes, it returns True, else False.
Below is a demonstration of the same −
my_tuple = (31, 45, 12, 56, 78, None, None) print("The tuple is : ") print(my_tuple) my_result = any(map(lambda elem: elem is None, my_tuple)) print("Does the tuple contain any None value ? " ) print(my_result)
The tuple is : (31, 45, 12, 56, 78, None, None) Does the tuple contain any None value ? True
- A tuple is defined and is displayed on the console.
- The lambda function is applied on each element in the tuple using 'map' method.
- The any function is called on this result and it is assigned to a variable.
- This variable is displayed on the console.
- Check for None Tuple in Python
- Python – Check if any list element is present in Tuple
- How to check if a matrix has any missing value in R?
- How to check if a data frame has any missing value in R?
- Check if variable is tuple in Python
- Check if element is present in tuple in Python
- Check if tuple and list are identical in Python
- Python – Test if tuple list has a single element
- Check if one tuple is subset of other in Python
- Check if element is present in tuple of tuples in Python
- Remove tuple from list of tuples if not containing any character in Python
- Check if any permutation of N equals any power of K in Python
- Python Pandas - Check if the index has NaNs
- Python - Check if two lists have any element in common
- Check if any interval completely overlaps the other in Python