python中的ord函数怎么使用

avatar
作者
筋斗云
阅读量:0

ord函数用于返回一个字符的Unicode码。使用方式如下:

ord(character)

其中,`character`为一个字符。ord函数将返回该字符的Unicode码。
示例:

print(ord('A'))  # 输出65 print(ord('a'))  # 输出97 print(ord('中'))  # 输出20013

注意:ord函数只能接受一个字符作为参数,不能传入多个字符或字符串。如果需要获取字符串中每个字符的Unicode码,可以使用循环遍历字符串,对每个字符使用ord函数。

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!