- 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
Compare tuples in Python
When it is required to compare tuples, the '<', '>', and '==' operators can be used.
it returns True or False depending on whether the tuples are equal to each other, less than or greater than one another.
Below is a demonstration of the same −
Example
my_tuple_1 = (87, 90, 31, 85) my_tuple_2 = (34, 56, 12, 5) print("The first tuple is :") print(my_tuple_1) print("The second tuple is :") print(my_tuple_2) print("Comparing the two tuples") print(my_tuple_1< my_tuple_2) print(my_tuple_1==my_tuple_2) print(my_tuple_2 > my_tuple_1)
Output
The first tuple is : (87, 90, 31, 85) The second tuple is : (34, 56, 12, 5) Comparing the two tuples False False False
Explanation
- Two tuples are defined, and are displayed on the console.
- They are compared using the '<', '>', and '==' operator.
- It is displayed as output on the console.
- Related Articles
- How do we compare two tuples in Python?
- How to compare two tuples in C#?
- Combining tuples in list of tuples in Python
- Count tuples occurrence in list of tuples in Python
- Updating Tuples in Python
- How to Concatenate tuples to nested tuples in Python
- Remove duplicate tuples from list of tuples in Python
- How to split Python tuples into sub-tuples?
- Basic Tuples Operations in Python
- Addition of tuples in Python
- Remove matching tuples in Python
- Pairwise Addition in Tuples in Python
- Addition in Nested Tuples in Python
- Python – Ordered tuples extraction
- Python – Extend consecutive tuples

Advertisements