当需要比较元组时,可以使用'<','>'和'=='运算符。
它会根据元组彼此相等,小于还是大于而返回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
定义了两个元组,并将其显示在控制台上。
使用'<','>'和'=='运算符对它们进行比较。
它在控制台上显示为输出。