python怎么比较元组的大小_在Python中,元组比较是如何工作的?

元组逐位比较:

将第一个元组的第一项与第二元组的第一项进行比较;如果它们不相等(即第一个大于或小于第二个)那么这就是比较的结果,否则考虑第二个项目,然后是第三个项目,依此类推.

Sequences of the same type also support comparisons. In particular, tuples and lists are compared lexicographically by comparing corresponding elements. This means that to compare equal, every element must compare equal and the two sequences must be of the same type and have the same length.

Lexicographical comparison between built-in collections works as follows:

For two collections to compare equal, they must be of the same type, have the same length, and each pair of corresponding elements must compare equal (for example, [1,2] == (1,2) is false because the type is not the same).

Collections that support order comparison are ordered the same as their first unequal elements (for example, [1,2,x] <= [1,2,y] has the same value as x <= y). If a corresponding element does not exist, the shorter collection is ordered first (for example, [1,2] < [1,2,3] is true).

如果不相等,则序列的排序与它们的第一个不同元素相同.例如,cmp([1,2,x],[1,2,y])返回与cmp(x,y)相同的值.如果相应的元素不存在,则较短的序列被认为较小(例如,[1,2]< [1,2,3]返回True).

注1:并不是指“小于”和“大于”,而是“在之前”和“在之后”:所以(0,1)“在”之前“(1,0).

注2:元组不能被视为n维空间中的向量,根据它们的长度进行比较.

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值