ord函数用于返回一个字符的Unicode码。使用方式如下:
ord(character)
其中,`character`为一个字符。ord函数将返回该字符的Unicode码。
示例:
print(ord('A')) # 输出65 print(ord('a')) # 输出97 print(ord('中')) # 输出20013
注意:ord函数只能接受一个字符作为参数,不能传入多个字符或字符串。如果需要获取字符串中每个字符的Unicode码,可以使用循环遍历字符串,对每个字符使用ord函数。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: python跨文件共享变量怎么实现