ord() 函数返回表示 Unicode 字符的整数。
示例
character = 'P'
# find unicode of P
unicode_char = ord(character)
print(unicode_char)
# Output: 80
ord() 语法
ord() 的语法是
ord(ch)
ord() 参数
ord() 函数接受一个参数
- ch - 一个 Unicode 字符
ord() 返回值
ord() 函数返回表示 Unicode 字符的整数。
示例:ord() 在 Python 中如何工作?
print(ord('5')) # 53
print(ord('A')) # 65
print(ord('$')) # 36
输出
53 65 36
顺便说一下,ord() 函数是 Python chr() 函数的逆函数。
另请阅读
