Python ord() 函数

Python 教程 · 2019-02-01 19:12:39

描述

ord() 函数是 chr() 函数(对于8位的ASCII字符串)或 unichr() 函数(对于Unicode对象)的配对函数,它以一个字符(长度为1的字符串)作为参数,返回对应的 ASCII 数值,或者 Unicode 数值,如果所给的 Unicode 字符超出了你的 Python 定义范围,则会引发一个 TypeError 的异常。

语法

以下是 ord() 方法的语法:

ord(c)

参数

  • c -- 字符。

返回值

返回值是对应的十进制整数。

实例

以下展示了使用 ord() 方法的实例:

>>>ord('a') 97 >>> ord('b') 98 >>> ord('c') 99

点击查看所有 Python 教程 文章: https://www.codercto.com/courses/l/8.html

查看所有标签

Elements of Programming

Elements of Programming

Alexander A. Stepanov、Paul McJones / Addison-Wesley Professional / 2009-6-19 / USD 39.99

Elements of Programming provides a different understanding of programming than is presented elsewhere. Its major premise is that practical programming, like other areas of science and engineering, mus......一起来看看 《Elements of Programming》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具