比较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 婆婆66岁祝福语简短
13 今天孩子高考祝福语简短
14 送彩票生日祝福语简短
15 分别祝福语简短情话英文
16 画室揭牌仪式祝福语简短
17 女友妈妈生日祝福语简短
18 离别赠言离职祝福语简短