Python注意事项(三)

  • Post author:
  • Post category:python


1.Python2 与 Python3 均不支持复数比较大小,Python2 中会抛出以下错误:

TypeError: no ordering relation is defined for complex numbers

Python3 中会抛出以下错误:

TypeError: ‘>’ not supported between instances of ‘complex’ and ‘complex’

2. Python2 与 Python3 均支持连续比较,3>2>2 相当于 3>2 and 2>2,后一个判断式为假,因此整个表达式都为假

3. (3,2)>(‘a’,’b’) Python2 支持数字与字符串之间的比较,而 Python3 则不支持, 会报以下错误:

TypeError: ‘>’ not supported between instances of ‘int’ and ‘str’

4. 字符串的比较与 tuple 类似,也是从第一个字符开始比较 ASCII 码,直到两个字符不相等为止。

字母与数字的ASCII 码大小范围是 “a-z” > “A-Z” > “0-9″,



版权声明:本文为qq_40229790原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。