python字符串之间用比较符实际上就是比较第一个字母的ASCII码大小
str1 = "abc"; str2 = "xyz"; str1>str2 true
通过内置函数 ord() 获得每个字符的 Unicode 编码进行大小比较
print(max(['1', '2', '3'])) # 3
print(max(['31', '2', '3'])) # 31
print(max(['13', '2', '3'])) # 3
print(max(['10', '11', '12'])) # 12
print(max(['13', '11', '12'])) # 13
print(ord('1')) # 49
print(ord('2')) # 50
print(ord('3')) # 51
# print(ord('10')) TypeError: ord() expected a character, but string of length 2 found
print(ord(' ')) # 32
上一篇:Go中方法与函数的区别是什么