- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
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 element is present in tuple in Python
When it is required to check if an element is present in the tuple or not, a simple loop 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.
Below is a demonstration of the same −
Example
my_tuple_1 = (23, 45, 12, 56, 78, 0) print("The first tuple is : ") print(my_tuple_1) N = 12 print("The value of 'N' has been initialized") my_result = False for elem in my_tuple_1 : if N == elem : my_result = True break print("Does the tuple contain the value mentioned ?") print(my_result)
Output
The first tuple is : (23, 45, 12, 56, 78, 0) The value of 'N' has been initialized Does the tuple contain the value mentioned ? True
Explanation
- A tuple is defined, and is displayed on the console.
- The value of 'N' is initialized.
- The loop is iterated over, and if the element 'N' is present in the tuple, a value is assigned 'True'.
- This value is assigned to a result.
- It is displayed as output on the console.
- Related Articles
- Python – Check if any list element is present in Tuple
- Check if element is present in tuple of tuples in Python
- Check if variable is tuple in Python
- Check if one tuple is subset of other in Python
- Check if substring present in string in Python
- How do you check if an element is present in a list in Java?
- Check if tuple has any None value in Python
- Check if tuple and list are identical in Python
- Python Program to check if a substring is present in a given string.
- Test if tuple is distinct in Python
- Check for None Tuple in Python
- Maximum element in tuple list in Python
- Python – Test if tuple list has a single element
- Python – Check if particular value is present corresponding to K key
- Check if elements of Linked List are present in pair in Python

Advertisements