Post

Python ord()

The ord() is a built-in python function that returns an integer representation of the specified Unicode character.

Python ord()

The syntax of ord() is:

1
2
ord("string")

ord() Parameters

The ord() function takes only one parameter as an argument:

  • string - A simple string.

Let see an example of ord() in python.

Example 1: how to use the ord() function in python?

1
2
3
4
5
6
print(ord('A')) # 65

print(ord('4')) # 52

print(ord('$')) # 36

Output:

1
2
3
4
65
52
36

Rules of ord()

  • The ord() function will only return an integer when a single string is passed.

You can also check the Python chr() function that does the total inverse from the Python ord() function.

This post is licensed under CC BY 4.0 by the author.