python_ord_函数_2021.6.5
程序员文章站
2022-04-27 18:40:46
...
函数ord(x)是返回字符x对应的Unicode编码
#注意看清楚是字符,不是字符串
给数字会报错
>>> ord(5)
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
ord(5)
TypeError: ord() expected string of length 1, but int found
给字符串也会报错
>>> ord('56')
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
ord('56')
TypeError: ord() expected a character, but string of length 2 found
给单字符不会报错
>>> ord('5')
53
上一篇: python_lower函数_2021-06-05
下一篇: divmod函数2021.6.5