Python Escape Sequences Beyond n and t A Practical Guide
Python Escape Sequences Beyond n and t
Python Tutorial > Legacy Escape Sequences > Low Level Escape Sequences > Python Escape Sequences Beyond \n and \t: A Practical Guide
Posted in

Python Escape Sequences Beyond \n and \t: A Practical Guide

Explore advanced Python escape sequences beyond \n and \t. Learn how \r, Unicode escapes, hex values, and control characters work with real examples and best practices.

Introduction

1. \r — Carriage Return

Example: Without Using \r

text = "Processing...Done"
print(text)

Example: Using \r

text = "Processing...\rDone"
print(text)

Example: Using \r Multiple Times

text = "Step 1\rStep 2\rStep 3"
print(text)

Rules to Remember

2. \b — Backspace

Example: Without Using \b

text = "HelloX"
print(text)

Explanation

Example: Using \b

text = "HelloX\b"
print(text)

Example: Using \b Multiple Times

text = "Python!!!\b\b\b"
print(text)

Example: Using \b at the Beginning of a String

text = "\bPython!!!"
print(text)

Why \b Is Rarely Used Today

Rules to Remember

3. \f — Form Feed

Example

text = "Page 1\fPage 2"
print(text)

Why \f Is Rarely Used Today

4. \v — Vertical Space (Vertical Tab)

Example: Without Using \v

text = "Line 1\nLine 2"
print(text)

Example: Using \v

text = "Line 1\vLine 2"
print(text)

Why \v Is Rarely Used Today

5. \ooo — Octal Value Escape

Basic Syntax

Example: Printing a Character Using Octal Value

text = "\101"
print(text)

Important Rules

Why \ooo Is Rarely Used Today

6. \xhh — Hexadecimal Value Escape

Basic Syntax

Example: Printing a Character Using Hex Value

text = "\x41"
print(text)

Example: Multiple Hex Escapes in One String

text = "\x48\x65\x6c\x6c\x6f"
print(text)
HexCharacter
48H
65e
6cl
6cl
6fo

Important Rules

Summary

7. \N{name} — Unicode Character by Name

Basic Syntax

Example: Using a Unicode Character Name

text = "\N{GREEK CAPITAL LETTER PI}"
print(text)

Example: Using Common Symbols

text = "Copyright \N{COPYRIGHT SIGN} 2025"
print(text)
text = "\N{INVALID NAME}"
Escape SequenceOutputDescription
\N{COPYRIGHT SIGN}©Copyright
\N{REGISTERED SIGN}®Registered trademark
\N{TRADE MARK SIGN}Trademark
\N{DEGREE SIGN}°Degree symbol
\N{SECTION SIGN}§Section symbol
Escape SequenceOutputDescription
\N{DOLLAR SIGN}$US Dollar
\N{EURO SIGN}Euro
\N{POUND SIGN}£British Pound
\N{YEN SIGN}¥Japanese Yen
\N{INDIAN RUPEE SIGN}Indian Rupee
Escape SequenceOutputDescription
\N{PLUS-MINUS SIGN}±Plus-minus
\N{MULTIPLICATION SIGN}×Multiplication
\N{DIVISION SIGN}÷Division
\N{NOT EQUAL TO}Not equal
\N{LESS-THAN OR EQUAL TO}Less than or equal
Escape SequenceOutputDescription
\N{LEFTWARDS ARROW}Left arrow
\N{RIGHTWARDS ARROW}Right arrow
\N{UPWARDS ARROW}Up arrow
\N{DOWNWARDS ARROW}Down arrow
Escape SequenceOutputDescription
\N{GREEK SMALL LETTER PI}πPi
\N{GREEK CAPITAL LETTER PI}ΠCapital Pi
\N{GREEK SMALL LETTER ALPHA}αAlpha
\N{GREEK SMALL LETTER BETA}βBeta

Important Rules

8. \uXXXX — 16-bit Unicode Escape

Basic Syntax

Example: Printing a Unicode Character

text = "\u03C0"
print(text)

Example: Multiple \uXXXX in One String

text = "\u03B1\u03B2\u03B3"
print(text)
Hex CodeCharacter
03B1α
03B2β
03B3γ

Important Rules

Example with Text and Symbol

text = "Area of circle = r² \u03C0"
print(text)
Area of circle = r² π

9. \UXXXXXXXX — 32-bit Unicode Escape

Basic Syntax

Example: Printing an Emoji

text = "\U0001F600"
print(text)
text = "\U0001F600"
print(text)

Example: Using Multiple 32-bit Unicode Escapes

text = "\U0001F60A \U0001F44B \U0001F680"
print(text)
Hex CodeCharacterDescription
0001F60A😊Smiling Face
0001F44B👋Waving Hand
0001F680🚀Rocket

Important Rules

Comparison with \uXXXX and \N{name}

EscapeRangeDigits / LengthNotes
\uXXXXBMP (U+0000 to U+FFFF)4 hex digits16-bit Unicode
\UXXXXXXXXFull Unicode (U+0000 to U+10FFFF)8 hex digits32-bit Unicode
\N{name}Full UnicodeName stringReadable, self-documenting

Example with Text and Emoji

text = "Rocket to the moon \U0001F680"
print(text)
Rocket to the moon 🚀

Mini Cheat Sheet: \uXXXX (16-bit) and \UXXXXXXXX (32-bit)

EscapeCharacterDescription
\u03B1αGreek small letter alpha
\u03B2βGreek small letter beta
\u03C0πGreek small letter pi
\u03A3ΣGreek capital letter sigma
EscapeCharacterDescription
\u00B1±Plus-minus
\u00D7×Multiplication
\u00F7÷Division
\u2260Not equal
EscapeCharacterDescription
\u0024$Dollar
\u20ACEuro
\u00A3£Pound
\u20B9Indian Rupee
EscapeCharacterDescription
\U0001F600😀Grinning face
\U0001F60A😊Smiling face
\U0001F44B👋Waving hand
\U0001F680🚀Rocket

10. \a (Bell / Alert) and \0 (Null Character)

\a — Bell / Alert

\0 — Null Character

text = "Hello\0World"
print(text)

Comparison Table of Escape Sequences

EscapeNameUsage Today
\rCarriage Return✔ Common in terminals
\bBackspace⚠ Limited
\fForm Feed❌ Rare
\vVertical Tab❌ Obsolete
\oooOctal Escape❌ Legacy
\xhhHex Escape✔ Binary data
\N{name}Unicode Name✔ Readable Unicode
\uXXXXUnicode (16-bit)✔ Common
\UXXXXXXXXUnicode (32-bit)✔ Emojis
\aBell⚠ System-dependent
\0Null Character✔ Low-level

Understanding Legacy and Low-Level Escape Sequences

What Is Legacy Code?

What Are Low-Level Escape Sequences?

What Is Low-Level Code?

Conclusion

Next Post
Python Escape Sequences Rules and Errors: A Complete Guide

2 thoughts on “Python Escape Sequences Beyond \n and \t: A Practical Guide

Leave a Reply

Your email address will not be published. Required fields are marked *