Differences between revisions 1 and 4 (spanning 3 versions)
Revision 1 as of 2004-10-13 02:33:44
Size: 411
Editor: 60
Comment:
Revision 4 as of 2004-10-13 02:50:04
Size: 951
Editor: 60
Comment:
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:
== python 元组比较语义怪怪 == == python 元组比较语义 怪怪 ==
Line 21: Line 21:
1 对于空tuple (), 与含有一个元素的tuple比较,cmp( (), (a)), 结果为1,即 () > (a) 为真 1 对于空tuple (), 与含有一个元素的tuple比较,cmp( (), (a)), 结果为1,即 () > (a) 为真
Line 23: Line 23:
2 对于空tuple (), 与含有2个元素的tuple比较,cmp( (), (a,b)), 结果为-1,即 () < (a,b) 为真 2   对于空tuple (), 与含有2个或更多元素的tuple比较,cmp( (), (a,b)), 结果为-1,即 () < (a,b) 为真
Line 25: Line 25:
3 3 对于非空含有不同数目元素tuple之间的比较, 比较的是元素个数

4 对于非空含有相同数目元素tuple之间的比较, 按照元素的字典序比较

第1条的语义与2,3,4不一致!,或者可以认为对空tuple ()特殊处理。

但是觉得 对于 < (or >)运算应该具有闭包关系:
    
    命题:if a<b and b<c then a<c
    
    应该成立

这里: 取 a=(3), b = (), c= (2): 嘿嘿,a<b b<c


没看Python文档, 还不清楚如何定义的.



python 元组比较语义 怪怪

Example

   1 ()<(1)
   2 (1)<(2)
   3 ()<(1,2)
   4 """result"""
   5 False
   6 True
   7 True

=== 怪怪===

1 对于空tuple (), 与含有一个元素的tuple比较,cmp( (), (a)), 结果为1,即 () > (a) 为真

2 对于空tuple (), 与含有2个或更多元素的tuple比较,cmp( (), (a,b)), 结果为-1,即 () < (a,b) 为真

3 对于非空含有不同数目元素tuple之间的比较, 比较的是元素个数

4 对于非空含有相同数目元素tuple之间的比较, 按照元素的字典序比较

第1条的语义与2,3,4不一致!,或者可以认为对空tuple ()特殊处理。

但是觉得 对于 < (or >)运算应该具有闭包关系:

  • 命题:if a<b and b<c then a<c 应该成立

这里: 取 a=(3), b = (), c= (2): 嘿嘿,a<b b<c

没看Python文档, 还不清楚如何定义的.

v-gyc/odd%tuple (last edited 2009-12-25 07:14:44 by localhost)