Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

The Python ord() function

The Python ord() function

Python built-in function Python built-in function


Description

The ord() function is the counterpart of chr() (for 8-bit ASCII strings) or unichr() (for Unicode objects). It takes a character (a string of length 1) as an argument and returns the corresponding ASCII or Unicode value. If the given Unicode character is outside the range defined by your Python build, a TypeError is raised.

Syntax

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


ord(c)

Parameters

Return Value

The return value is the corresponding decimal integer.


Example

The following examples demonstrate the use of the ord() method:

ord

(

'

a

'

)

97

ord

(

'

b

'

)

98

ord

(

'

c

'

)

99

Python built-in function Python built-in function