比较Python中的元组
当需要比较元组时,可以使用'<','>'和'=='运算符。
它会根据元组彼此相等,小于还是大于而返回True或False。
以下是相同的演示-
示例
my_tuple_1 = (87, 90, 31, 85)
my_tuple_2 = (34, 56, 12, 5)
print("Thefirsttupleis:")
print(my_tuple_1)
print("Thesecondtupleis:")
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)输出结果Thefirsttupleis: (87, 90, 31, 85) Thesecondtupleis: (34, 56, 12, 5) Comparing the two tuples False False False
解释
定义了两个元组,并将其显示在控制台上。
使用'<','>'和'=='运算符对它们进行比较。
它在控制台上显示为输出。
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短