print(4 > 5)
Run Code Online (Sandbox Code Playgroud)
输出为 False,使用基本数学很容易理解
print("a" > "A")
Run Code Online (Sandbox Code Playgroud)
输出为真
python 如何比较 a 和 A ?
Python 字符串比较是使用两个字符串中的字符来执行的。将两个字符串中的字符一一进行比较。当找到不同的字符时,就会比较它们的 Unicode 值。Unicode 值较低的字符被认为较小。
Unicode的值为,'A'而65for 'a'it 的值为97。
该ord()函数返回Unicode一个字符的值。
ord('A') # returns 65
ord('a') # returns 97
ord('AA') # ERROR: ord() expects a string of length 1.
Run Code Online (Sandbox Code Playgroud)