CBSE Class 11 : Python | Tuples 7

Comparing Tuples

We can compare two tuples using the comparison operators i.e. <, >, <=, >=, == and !=. Python internally compares individual elements of two tuples.

 

Example:
a=(1,2)
b=(1,2)
print(a==b)
print(a>b)
print(a<b)
output:
True
False
False

Example:
a=(1,2,3)
b=(1,2)
print(a==b)
print(a<b)
print(a>b)
Output:
False
False
True
Example:
a=(1,2)
b=(1.4,3.4)
print(a==b)
print(a>b)
print(a<b)
Output:
False
False
True

a=(1,2)
b=(1,2)
print(a==b)
print(a>b)
print(a<b)

Output:

True
False
False

a=(1,2,3)
b=(1,2)
print(a==b)
print(a<b)
print(a>b)

Output:

False
False
True