以我目前的理解,ord返回编码,chr返回字符串
现在试试:
ord("ab")
然后得到报错:
TypeError: ord() expected a character, but string of length 2 found
但如果加上\x就好了:
>>> ord("\xab")
171
>>>
不过这个方法仅对两个字母或数字有效
ord("\xabc")
Traceback (most recent call last):
File "", line 1, in
ord("\xabc")
TypeError: ord() expected a character, but string of length 2 found
ord("\x123")
Traceback (most recent call last):
File "", line 1, in
ord("\x123")
TypeError: ord() expected a character, but string of length 2 found现在,谁能告诉我,这个\x究竟是什么?网上很多资料都没有提到
\x表示十六进制编码转义(因为正好abcdef都是合法的16进制数字,其实不是字面的ab),你字符串只能取1个字符