Python 中区分大小写的字符串比较

Case sensitive string comparison in Python

以下代码:

if "IAMBIG" > "iambig":
      print("True")
else:
      print("False")

结果:

False

由于 Python 区分大小写,我知道检查是否相等会导致上述 if 语句中的 False。但是,我不确定 string 比较在检查 - "greater than"(或小于)条件时如何工作。

任何人都可以解释为什么我在上面的 if 语句中得到 False 吗?

Python 3 将字符串作为 unicode 字符序列进行比较。由于字符 I 的 unicode 编号是 U+0049 而字符 i 的 unicode 编号是 U+0069,因此比较 "I..." > "i..." returns False.

我一般拉丁文小写字母的数字大于大写字母,这会使大写字符串 "smaller" 在使用比较运算符时比小写字母大写。

作为参考,这里有一个 link 到基本的拉丁 unicode 块:http://unicode-table.com/en/blocks/basic-latin/