python中的ord函数如何使用
ord函数用于返回一个字符的Unicode码。使用方式以下:
ord(character)
其中,`character`为一个字符。ord函数将返回该字符的Unicode码。
示例:
print(ord('A'))#输出65 print(ord('a'))#输出97 print(ord('中'))#输出20013
注意:ord函数只能接受一个字符作为参数,不能传入多个字符或字符串。如果需要获得字符串中每一个字符的Unicode码,可使用循环遍历字符串,对每一个字符使用ord函数。
TOP