新闻资讯

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻资讯列表

python中的ord函数如何使用,python中ord(x)的作用

发布时间:2023-11-04 11:39:21

python中的ord函数如何使用

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

ord(character)

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

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

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