描述
Given a string representing one Unicode character, return an integer representing the Unicode code point of that character. For example, ord('a')
returns the integer 97
and ord('€')
(Euro sign) returns 8364
. This is the inverse of chr()
.
总结
在Python3中,函数默认支持unicode,所以直接使用上述两函数即可。
例子
通过chr()和ord()联合起来使用,我们就可以对字符串进行相关运算的转换。
比如一个字符串str1,转化成另一个字符串str2, 使得 str2[i] = str1[i] - i.
str1 = "eb;3ej8h"
for i in range(0, len(str1)):
print chr((ord(str1[i])-i)),
Output: e a 9 0 a e 2 a
网友评论