Escape text with Python \u escapes

Convert text to Python \UXXXXXXXX and \uXXXX escape sequences in your browser — safe for source files, config formats and debugging invisible characters. Nothing uploaded.

Get text into Python source safely: every non-ASCII character becomes \UXXXXXXXX — eight hex digits, Python's native full-code-point form — so 中 becomes \U00004e2d and 🎉 becomes \U0001f389 with no surrogate pairing needed. With printable ASCII kept readable, the output is a valid Python 3 string literal you can paste into any .py file regardless of encoding luck.

The escaped form is also how you debug invisible problems: control characters, zero-width spaces and bidirectional marks all become explicit escapes, which makes it a good cleaning step before text hits regexes, identifiers or config formats that only accept ASCII.

Python also accepts the shorter \uXXXX (BMP only, surrogate pairs for emoji) — the text-to-Unicode converter emits that dialect too. All conversion happens locally in your browser.

Frequently asked questions

\u or \U in Python?
Both work in Python 3 string literals: \uXXXX takes exactly four hex digits (BMP only), \UXXXXXXXX takes exactly eight (any code point). This page emits \UXXXXXXXX so emoji and rare hanzi need no surrogate pairs.
Does it work in raw strings?
No — r'' strings keep backslashes literal, so the escapes stay as text. Use normal strings when you want the escapes interpreted. Inside re patterns the \u and \U forms are understood by the regex engine itself.
Why not just save the file as UTF-8?
You usually can — Python 3 assumes UTF-8 source. Escaping matters for data you don't control: config formats, JSON-in-strings, protocols with ASCII limits, or when you need invisible characters to become visible for debugging.