比较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
解释
定义了两个元组,并将其显示在控制台上。
使用'<','>'和'=='运算符对它们进行比较。
它在控制台上显示为输出。
热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短