Python ord()

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() 函数的逆函数。


另请阅读

你觉得这篇文章有帮助吗?

我们的高级学习平台,凭借十多年的经验和数千条反馈创建。

以前所未有的方式学习和提高您的编程技能。

试用 Programiz PRO
  • 交互式课程
  • 证书
  • AI 帮助
  • 2000+ 挑战