Computer >> 컴퓨터 >  >> 프로그램 작성 >> Python

Python에서 튜플 비교

<시간/>

튜플을 비교할 때 '<', '>', '==' 연산자를 사용할 수 있습니다.

튜플이 서로 같은지, 작거나 큰지에 따라 True 또는 False를 반환합니다.

아래는 동일한 데모입니다 -

예시

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)

출력

The first tuple is :
(87, 90, 31, 85)
The second tuple is :
(34, 56, 12, 5)
Comparing the two tuples
False
False
False

설명

  • 두 개의 튜플이 정의되어 콘솔에 표시됩니다.
  • '<', '>' 및 '==' 연산자를 사용하여 비교됩니다.
  • 콘솔에 출력으로 표시됩니다.