- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 variable is tuple in Python
When it is required to check if a variable is a tuple, the 'type' method can be used. A tuple is an immutable data type. It means, values once defined can't be changed by accessing their index elements. If we try to change the elements, it results in an error. They are important contains since they ensure read-only access.
The 'type' method checks to see the type of the iterable/value that is passed to it as an argument.
Below is a demonstration of the same −
my_tuple_1 = (7, 8, 0, 3, 45, 3, 2, 22, 4) print ("The tuple is : " ) print(my_tuple_1) my_result = type(my_tuple_1) is tuple print("Is the given variable a tuple ? ") print(my_result)
The tuple is : (7, 8, 0, 3, 45, 3, 2, 22, 4) Is the given variable a tuple ? True
- A tuple is defined, and is displayed on the console.
- The type of the tuple is examined, and the 'is' and 'tuple' operators are used to check if it is a tuple type.
- This result is assigned to a value.
- It is displayed as output on the console.
- Python - Check if a variable is string
- Check if element is present in tuple in Python
- Check if one tuple is subset of other in Python
- Check if element is present in tuple of tuples in Python
- Python – Check if any list element is present in Tuple
- Check if tuple has any None value in Python
- Check if tuple and list are identical in Python
- Test if tuple is distinct in Python
- How to check if type of a variable is string in Python?
- How do I check if a Python variable exists?
- How to check if a variable is NULL in C/C++?