89DEVs

Python ord() function

overview of ord()

The ord() function returns the integer representation of the given unicode character. It is the reverse function of chr(), which returns the unicode character from the given integer representation.

use of ord()

The ord() function is used to convert any Unicode character to its integer representation. # use of ord() function a = ord('a') b = ord('b') c = ord('c') print(a) print(b) print(c) The letters 'a', 'b', and 'c' are converted to integer representations and then assigned to the variables a, b, and c. Then, the variables are printed. 97 98 99 The integers can be reversed to the unicode characters by the chr() function.

syntax of ord()

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

arguments of ord()

The ord() function accepts a single parameter, which is required. The argument is the unicode character to be returned as an integer representation. If no argument or a wrong type or argument is provided, a TypeError exception is raised.

return value of ord()

The ord() function returns an integer value representing the Unicode character.

                
        

Summary


Click to jump to section