HOWTO · Python

How to Print Unicode Characters in Python

This tutorial demonstrates how to print unicode characters in Python

On this page

Python strings can contain Unicode characters directly, and print() writes those characters to standard output. If you know a character’s hexadecimal code point or Unicode name, you can put it in a string with an escape sequence, build it with chr(), or look it up with unicodedata.lookup().

A Unicode code point is written as U+ followed by a hexadecimal number. For example, U+2612 represents ☒ and U+7687 represents 皇. The three methods below create the same string, ☒皇ÉÉ.

Method 1: Using Unicode Escape Sequences

In a Python string literal, \u is followed by exactly four hexadecimal digits, while \U is followed by eight. Use \u for code points through U+FFFF; use \U for code points above that range. The extra leading zeroes in the \U form are part of its eight-digit width.

Run this example:

unicode_text = "\u2612\u7687\u00C9\u00C9"
print(unicode_text)
☒皇ÉÉ

Each escape contributes one character to the string. Python interprets these escapes when it reads the string literal, so the printed text contains the characters rather than the escape notation.

Method 2: Using the chr() Function

Use chr() when your code already has integer code points, such as values read from data. It returns a one-character string for the supplied code point; concatenate those strings to make a longer result.

unicode_text = chr(0x2612) + chr(0x7687) + chr(0x00C9) + chr(0x00C9)
print(unicode_text)
☒皇ÉÉ

The 0x prefix marks each integer as hexadecimal. The resulting string can be handled like any other Python string.

Method 3: Using Unicode Names

When a character’s name is easier to remember than its number, use unicodedata.lookup() from Python’s standard unicodedata module. It returns the character associated with an exact Unicode name. Join the returned strings and pass the result to print():

import unicodedata

unicode_text = (
    unicodedata.lookup("BALLOT BOX WITH X")
    + unicodedata.lookup("CJK UNIFIED IDEOGRAPH-7687")
    + unicodedata.lookup("LATIN CAPITAL LETTER E WITH ACUTE")
    + unicodedata.lookup("LATIN CAPITAL LETTER E WITH ACUTE")
)
print(unicode_text)
☒皇ÉÉ

Use the spelling listed in the Unicode character names. A misspelled or unknown name cannot be looked up, so check the name before using it.

Additional Tips

  • A terminal, editor, or font must support the selected characters to display them as intended. If the output looks like boxes or question marks, check the display environment; the string may still contain the intended characters.
  • Consult a Unicode character listing when you need a code point or a character name. Keep the hexadecimal digits and escape width aligned: four digits after \u, or eight after \U.
  • You can also type visible Unicode characters directly into a Python source file when the file and editing environment preserve them correctly.

Conclusion

Use escape sequences when you know the hexadecimal code points, chr() when your code has integer values, and unicodedata.lookup() when you have Unicode names. All three approaches create ordinary Python strings that print() can send to output.