比较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 虎年五一祝福语大全简短
18 出阁宴祝福语姐姐简短