Python String Escape & Unescape
Escape Unicode text for a single- or double-quoted Python string literal, or decode Python's standard simple, octal, hexadecimal, and Unicode escapes without executing Python code.
Python String Escape & Unescape workspace
Press Ctrl/Cmd + Enter to convert. Processing stays in this tab and input is limited to 500,000 characters.
Python String Escape & Unescape example
Double-quoted output leaves the single quotes and Unicode snake readable.
Example input
Path: C:\tools
Message: 'ready'
Unicode: 🐍Expected output
"Path: C:\\tools\nMessage: 'ready'\nUnicode: 🐍"How to use Python String Escape & Unescape
- 1
Choose Escape or Unescape.
- 2
For escaping, choose single or double quote style and whether to wrap the result.
- 3
Optionally convert non-ASCII code points to \u or \U escapes.
- 4
Paste or load text and run the conversion.
- 5
Review the result before copying it into Python source.
What this tool does
Escape mode chooses single or double quote delimiters, protects the selected quote and backslashes, represents controls with familiar Python escapes, and can leave Unicode readable or emit fixed-width Unicode escapes.
Unescape mode accepts a quoted literal or only its contents. It decodes Python simple escapes, octal values, two-digit hexadecimal values, and four- or eight-digit Unicode values while preserving currently unrecognized escapes as Python does.
The converter handles ordinary str-literal contents only. It never calls eval, never executes f-string expressions, and reports incomplete numeric escapes or unmatched quotes.
Features and options
- Single- and double-quoted literal output
- Optional delimiters
- Readable Unicode by default
- \uXXXX and \UXXXXXXXX output
- Simple, octal, hex, and Unicode decoding
- Unknown-escape preservation
- Strict incomplete numeric errors
- No eval or code execution
- 500,000-character local limit
Technical information
Ordinary Python str literals recognize backslash-newline, simple control escapes, up to three octal digits, exactly two hexadecimal digits after \x, and fixed-width Unicode forms. Unicode named escapes require a Unicode name database and are outside this lightweight decoder.
Python 3.12 and later warns about unrecognized escape sequences even though the backslash is currently preserved. The decoder mirrors preservation; it does not imply that such source will remain warning-free or valid in future Python versions.
Raw strings, bytes literals, triple-quoted strings, f-strings, and template strings have distinct prefix or delimiter semantics. They are not inferred from ordinary converted contents.
Common use cases
- Preparing test fixtures
- Embedding copied multiline text
- Inspecting repr-like output
- Decoding Unicode escapes in sample data
- Making tabs and line breaks visible
- Switching quote style for source snippets
Limitations
- Named \N{...} Unicode escapes are not decoded.
- Raw, bytes, f-, t-, and triple-quoted literal forms are not parsed.
- Unrecognized escapes are preserved but may trigger SyntaxWarning or become errors in future Python versions.
- The tool does not evaluate adjacent literals or expressions.
- It does not determine a file's source encoding or normalize Unicode.
Related tools
References & Sources
Defines Python string prefixes, delimiters, recognized escapes, raw strings, and unrecognized-escape behavior.
Verified 2026-08-13 ↗Python Software Foundation · Official DocumentationPython Standard Types — Text Sequence TypeDocuments Python's Unicode str type represented by ordinary string literals.
Verified 2026-08-13 ↗Python Software Foundation · Official DocumentationPython CodecsDocuments Python codec concepts and escape-oriented text encodings relevant when moving between bytes and strings.
Verified 2026-08-13 ↗Python Software Foundation · Official DocumentationPython Unicode HOWTOExplains code points, encodings, Unicode strings, and escape notation in Python programs.
Verified 2026-08-13 ↗Python String Escape & Unescape FAQ
Does unescape use Python eval or unicode_escape?
No. A dedicated local parser decodes the documented ordinary-literal forms, so the input is never executed as Python code.
Why are unknown escapes preserved?
Current Python ordinary strings leave unrecognized escapes unchanged, although modern Python emits a SyntaxWarning and may make them errors in a future release.
Can it decode \N{UNICODE NAME}?
Not currently. Named escapes need Unicode name lookup; use \u or \U input with this tool.
Does it support raw strings?
No. Raw strings deliberately change backslash processing and have special quote-ending constraints, so they are outside this ordinary-literal converter.
What happens to emoji when Unicode escaping is enabled?
A supplementary code point is emitted as one eight-digit \U escape. With the option off, the emoji remains readable Unicode.
Can I paste a complete quoted literal?
Yes, for a single ordinary single- or double-quoted literal. Prefixes, triple quotes, concatenation, f-strings, and expressions are not parsed.