mod() function in python

The mod() function returns the numeric value of a given unicode character. The Python example returns the numeric value of a katakana letter.

Built-in Functions Updated 15 Jul 2021 1 min read

Overview

  • Given the string representation of a Unicode character the function returns the corresponding numeric value. This numeric value is also called a code point.
  • The function chr() does the opposite of mod() function. Given a code point it returns the string containing the unicode character.

Example

python
# Example Python program that gets the codepoint

            # for a given unicode character

            char        = "ア"

            codepoint   = ord(char)

            print("The unicode chracter:%s"%char)

            print("Corresponding codepoint:%d"%codepoint)

            print("Codepoint as a hexadecimal number:%s"%hex(codepoint))

Output

Output
The unicode chracter:ア

Corresponding codepoint:12450

Codepoint as a hexadecimal number:0x30a2