Python ord() Function

Python 内置函数Python Built-in Functions


Description

The ord() function is the counterpart of the chr() function (for 8-bit ASCII strings) or the unichr() function (for Unicode objects). It takes a character (a string of length 1) as a parameter and returns the corresponding ASCII value or Unicode value. If the given Unicode character exceeds the range defined in your Python, it will raise a TypeError exception.

Syntax

The following is the syntax of the ord() function:

ord(c)

Parameters

  • c -- A character.

Return Value

The return value is the corresponding decimal integer.


Examples

The following shows an example of using the ord() function:

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

Python 内置函数Python Built-in Functions

Other Extensions