了解原理和相關知識
-
字元串按位比較,兩個字元串第一位字元的ascii碼誰大,字元串就大,不再比較後面的;第一個字元相同就比第二個字元串,以此類推,需要注意的是空格的ascii碼是32,空(null)的ascii碼是0
https://zhidao.baidu.com/question/558202137825309252.html
- ord 函數接受一個字元
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