---
description: Escape characters or sequences are illegal characters for Python and never get printed as part of the output.
title: Python Escape Character Sequences (Examples)
image: https://www.guru99.com/images/python-escape-character-sequences.png
---

 

[Skip to content](#main) 

**⚡ Smart Summary**

Python escape character sequences use a backslash prefix to represent special characters inside strings. Lessons cover newline, tab, backslash, quote escapes, raw strings, and the built-in chr() and ord() functions for character codes.

* ⌫ **Backslash Prefix:** Every escape sequence begins with a backslash.
* ↵ **Newline \\n:** Inserts a line break in printed text or files.
* ⇥ **Tab \\t:** Inserts a horizontal tab for column alignment.
* 🚫 **Backslash \\\\:** Represents a single literal backslash.
* 📝 **Raw Strings:** Prefix with r to disable escape interpretation.
* 🔢 **chr() and ord():** Convert between Unicode code points and characters.

[ Read More ](javascript:void%280%29;) 

![Python Escape Character Sequences](https://www.guru99.com/images/python-escape-character-sequences.png)

Escape characters or sequences are illegal characters for Python and never get printed as part of the output. When backslash is used in Python programming, it allows the program to escape the next characters.

Following would be the syntax for an escape sequence

**Syntax:** 

\Escape character

**Explanation:** 

Here, the escape character could be t, n, e, or backslash itself.

## Types of Escape Sequence

Escape characters can be classified as non-printable characters when backslash precedes them. The print statements do not print escape characters.

Here is a list of Escape Characters

| Code   | Description            |
| ------ | ---------------------- |
| \\’    | Single quotation       |
| \\\\   | Backslash              |
| \\n    | New Line               |
| \\r    | Carriage return        |
| \\t    | Tab                    |
| \\b    | Backspace              |
| \\f    | Form feed              |
| \\ooo  | Octal equivalent       |
| \\xhhh | Hexadecimal equivalent |

The classification above is clearest with concrete examples to follow.

## Example Usage of Various Escape Characters

| Escape character | Function                                                                                                                                                                                                                            | Example Code                                   | Result    |
| ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------- | --------- |
| \\n              | The [new line character](https://www.guru99.com/print-without-newline-python.html) helps the programmer to insert a new line before or after a string.                                                                              | txt = “Guru\\n99!”print(txt)                   | Guru99    |
| \\\\             | This escape sequence allows the programmer to insert a backslash into the Python output.                                                                                                                                            | txt = “Guru\\\\99!”print(txt)                  | Guru\\99! |
| \\xhh            | Use a backslash followed by a hexadecimal number.This is done by printing in backslash with the hexadecimal equivalent in double quotes.                                                                                            | txt = “\\x47\\x75\\x72\\x75” + “99!”print(txt) | Guru99!   |
| \\ooo            | To get the integer value of an octal value, provide a backslash followed by ooo or octal number in double-quotes.It is done by printing in a backslash with three octal equivalents in double quotes.                               | txt = ‘\\107\\125\\122\\125’+ “99!”print(txt)  | GURU99!   |
| \\b              | This escape sequence provides backspace to the [Python string](https://www.guru99.com/learning-python-strings-replace-join-split-reverse.html). It is inserted by adding a backslash followed by “b”.“b” here represents backslash. | txt = “Guru\\b99!”print(txt)                   | Gur99!    |
| \\f              | It helps in the interpolation of literal strings                                                                                                                                                                                    | txt = “Guru\\f99!”print(txt)                   | Guru99!   |
| \\r              | It helps you to create a raw string                                                                                                                                                                                                 | txt = “Guru\\r99!”print(txt)                   | 99!u      |
| \\’              | It helps you to add a single quotation to string                                                                                                                                                                                    | txt = “Guru\\’99!”print(txt)                   | Guru’99!  |

### RELATED ARTICLES

* [Python Variables: How to Define/Declare String Variable Types ](https://www.guru99.com/variables-in-python.html "Python Variables: How to Define/Declare String Variable Types")
* [Difference Between Python and C++ ](https://www.guru99.com/python-vs-c-plus-plus.html "Difference Between Python and C++")
* [Python Array – Define, Create ](https://www.guru99.com/python-arrays.html "Python Array – Define, Create")
* [Python List index() with Example ](https://www.guru99.com/python-list-index.html "Python List index() with Example")

## What Does “\\t” Do in Python?

The t alphabet in Python represents a space. It enables you to insert space or tab between strings in a code. It helps us to have space in the Python program when there is a need for it. To eliminate the usage of keyboard space, the coders utilize tab escape sequences.

Following is the syntax for a tab escape sequence.

**Syntax:** 

“\t”

**Example:** 

In this example, the string used is “Guru99”. The program will put a tab or a space between Guru and 99.

**Python Code:**

TextExample="Guru\t99"
print (TextExample)

**Output:**

Guru 99

**Explanation:**

In the above example, instead of adding space using a keyboard, the program helps us by putting a space or a tab between the string “Guru99”. It also provides a space at the precise location where the escape sequence is added.

## When to use “\\t” in Python?

The escape sequence tab is utilized to put a horizontal tab between words and hence helps manipulate python strings. However, If the escape sequence tab is not used, the programmer has to manually add a space between every word of the string.

You can transform it into a time-consuming exercise. Moreover, the space added between different keywords may or may not be precise in its placement.

Here is an example that displays the manual addition of a space between words and the use of an escape sequence between words.

**Python Code:**

print("Manually Added  space in string Guru   99")
TextExample="Use\tof\ttab\tto\tadd\tspace\tGuru\t99"
print(TextExample)

**Output:**

Manually Added space in string Guru   99
Use	of	tab	to	add	space	Guru	99

**Explanation:**

The programmer manually added space between words in the above code, so the placement was not precise. When the escape sequence tab was applied, the program automatically provided the precise location of space between words.

## Application of built-in function Chr () and Ord ()

The Chr () function is a built function that takes a single argument as input. The function takes Unicode characters as an input which ranges from 0 to 1,114 and 111, respectively. The function can be used as the substitute for escape sequence “\\t” to put a space between two words.

The syntax for the Chr function is represented below: –

**Syntax: –**

Chr(Unicode character)

The tab has the Unicode character 9\. Use the following Python command to arrive at the Unicode character as shown below: –

**Python Code:**

print("Unicode character of the tab is")
Ord=ord('\t')
print(Ord)

**Output:**

Unicode character of the tab is
9

**Explanation:**

The above code provides the Unicode character for the tab. It can be used as an input for the Chr function. Use of Chr (9) would allow us to create a substitute for a tab escape sequence.

This code is an example of how to use Chr (9), as shown below:

**Python Code:**

TextExample="Guru+chr(9)+99"
print(TextExample)

**Output:**

Guru	99

The above function, however, is deprecated for version 3 and above.

## FAQs

⚡ What is an escape character in Python?

A backslash followed by one or more characters that represents something not easily typed, such as newline (\\n), tab (\\t), or a literal backslash (\\\\).

🤖 How does AI help with Python escape sequences?

AI assistants explain unfamiliar sequences, suggest raw strings for regex and paths, and warn when escapes break f-strings.

💡 When should I use a raw string in Python?

Use raw strings (r””) for file paths, regex patterns, and text where backslashes should be literal.

🔤 What does \\t do inside a Python string?

\\t inserts a horizontal tab. Display width depends on the terminal tab stop, typically four or eight spaces.

📝 Can a raw string end with a backslash?

Not directly. r”hello\\” raises SyntaxError because the backslash escapes the closing quote. Concatenate a separate backslash if needed.

🔢 Difference between chr() and ord()?

ord(c) returns the integer Unicode code point for a one-character string. chr(n) returns the character whose code point is n. They are exact inverses.

🛡️ Do escape characters work in f-strings?

Yes, but not directly inside {} expressions. Compute escapes in variables first or use concatenation.

🤖 Can AI debug Python escape sequence errors?

Yes. AI interprets SyntaxError from broken escapes and recommends raw string fixes for Windows paths.

#### Summarize this post with:

ChatGPT Perplexity Grok Google AI 

**Stay Updated on AI** **Get Weekly AI Skills, Trends, Actionable Advice.** 

##### Sign up for the newsletter

Subscribe for Free 

You have successfully subscribed.  
Please check your inbox. 

![AI-Newsletter]() Chosen by over **350,000+** professionals 

[Scroll to top ](#wrapper)Scroll to top 

× 

Toggle Menu Close 

Search for: 

Search

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.guru99.com/#organization","name":"Guru99","sameAs":["https://www.facebook.com/Guru99Official","https://twitter.com/guru99com"],"logo":{"@type":"ImageObject","@id":"https://www.guru99.com/#logo","url":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","contentUrl":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","caption":"Guru99","inLanguage":"en-US"}},{"@type":"WebSite","@id":"https://www.guru99.com/#website","url":"https://www.guru99.com","name":"Guru99","publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https://www.guru99.com/images/python-escape-character-sequences.png","url":"https://www.guru99.com/images/python-escape-character-sequences.png","width":"700","height":"250","caption":"Python Escape Character Sequences","inLanguage":"en-US"},{"@type":"BreadcrumbList","@id":"https://www.guru99.com/python-escape-characters.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":"1","item":{"@id":"https://www.guru99.com","name":"Home"}},{"@type":"ListItem","position":"2","item":{"@id":"https://www.guru99.com/python","name":"Python"}},{"@type":"ListItem","position":"3","item":{"@id":"https://www.guru99.com/python-escape-characters.html","name":"Python Escape Character Sequences (Examples)"}}]},{"@type":"WebPage","@id":"https://www.guru99.com/python-escape-characters.html#webpage","url":"https://www.guru99.com/python-escape-characters.html","name":"Python Escape Character Sequences (Examples)","dateModified":"2026-06-23T19:25:07+05:30","isPartOf":{"@id":"https://www.guru99.com/#website"},"primaryImageOfPage":{"@id":"https://www.guru99.com/images/python-escape-character-sequences.png"},"inLanguage":"en-US","breadcrumb":{"@id":"https://www.guru99.com/python-escape-characters.html#breadcrumb"}},{"@type":"Person","@id":"https://www.guru99.com/author/logan","name":"Logan Young","description":"I'm Logan Young, an expert in Python, providing top-tier tutorials and guides to enhance your coding skills and streamline your learning journey.","url":"https://www.guru99.com/author/logan","image":{"@type":"ImageObject","@id":"https://www.guru99.com/images/logan-young-author.png","url":"https://www.guru99.com/images/logan-young-author.png","caption":"Logan Young","inLanguage":"en-US"},"worksFor":{"@id":"https://www.guru99.com/#organization"}},{"articleSection":"Python","headline":"Python Escape Character Sequences (Examples)","description":"Escape characters or sequences are illegal characters for Python and never get printed as part of the output.","keywords":"python","speakable":{"@type":"SpeakableSpecification","cssSelector":[".entry-title",".summary"]},"@type":"Article","author":{"@id":"https://www.guru99.com/author/logan","name":"Logan Young"},"dateModified":"2026-06-23T19:25:07+05:30","image":{"@id":"https://www.guru99.com/images/python-escape-character-sequences.png"},"copyrightYear":"2026","name":"Python Escape Character Sequences (Examples)","subjectOf":[{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"What is an escape character in Python?","acceptedAnswer":{"@type":"Answer","text":"A backslash followed by one or more characters that represents something not easily typed, such as newline (n), tab (t), or a literal backslash (\\)."}},{"@type":"Question","name":"How does AI help with Python escape sequences?","acceptedAnswer":{"@type":"Answer","text":"AI assistants explain unfamiliar sequences in source code, suggest raw strings for regex and file paths, and warn when escape characters interfere with f-string expressions."}},{"@type":"Question","name":"When should I use a raw string in Python?","acceptedAnswer":{"@type":"Answer","text":"Use raw strings (r\"\") for file paths, regular expression patterns, and any text where backslashes should appear literally rather than as escape prefixes."}},{"@type":"Question","name":"What does t do inside a Python string?","acceptedAnswer":{"@type":"Answer","text":"t inserts a horizontal tab character. The display width depends on the terminal or editor's tab stop, typically four or eight spaces."}},{"@type":"Question","name":"Can a raw string end with a backslash?","acceptedAnswer":{"@type":"Answer","text":"Not directly. r\"hello\" raises SyntaxError because the backslash escapes the closing quote. Concatenate a separate backslash if needed."}},{"@type":"Question","name":"Difference between chr() and ord()?","acceptedAnswer":{"@type":"Answer","text":"ord(c) returns the integer Unicode code point for a one-character string. chr(n) returns the character whose code point is n. They are exact inverses."}},{"@type":"Question","name":"Do escape characters work in f-strings?","acceptedAnswer":{"@type":"Answer","text":"Yes, but you cannot place a backslash directly inside the {} expression part of an f-string. Compute escapes in variables first or use concatenation."}},{"@type":"Question","name":"Can AI debug Python escape sequence errors?","acceptedAnswer":{"@type":"Answer","text":"Yes. AI coding tools interpret SyntaxError messages from broken escapes, recommend raw string fixes, and rewrite Windows path strings with proper r-prefixes."}}]}],"@id":"https://www.guru99.com/python-escape-characters.html#schema-1119156","isPartOf":{"@id":"https://www.guru99.com/python-escape-characters.html#webpage"},"publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US","mainEntityOfPage":{"@id":"https://www.guru99.com/python-escape-characters.html#webpage"}}]}
```
