描述
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()
.
總結(jié)
在Python3中狰右,函數(shù)默認(rèn)支持unicode,所以直接使用上述兩函數(shù)即可。
例子
通過chr()和ord()聯(lián)合起來使用,我們就可以對字符串進(jìn)行相關(guān)運算的轉(zhuǎn)換。
比如一個字符串str1,轉(zhuǎn)化成另一個字符串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