为什么表达式'a'>'b'在Python中返回false?

时间:2019-11-09 13:48:11

标签: python python-3.x

print('a'>'b') 返回假 与此类似 打印('a'>'A') 返回True

2 个答案:

答案 0 :(得分:3)

Python对字符串使用字典顺序。这意味着它使用Unicode点号对字符进行排序。

参考: https://docs.python.org/3/tutorial/datastructures.html#comparing-sequences-and-other-types

您可能会发现这很有用: https://en.wikipedia.org/wiki/List_of_Unicode_characters

答案 1 :(得分:-1)

Python 3使用Unicode

每个字符都有一个根据ASCII表的值:

https://www.cs.cmu.edu/~pattis/15-1XX/common/handouts/ascii.html

'a'= 97

'b'= 98

'A'= 65

97> 98 返回假的原因

相关问题