What is escape sequence?

The sequence of character which has indirect meaning when it placed within double quotes.

It will optimize some the repetitive tasks while programming.


While printing some statement, if you want to give horizontal tab (usually four spaces) in between every word like below,


#escape sequence example

print("Happy    New    Year")

Here, we manually gave four space between each word. This can be achieved easily with \t escape sequence.

Like below,


#escape sequence in python


Useful Escape Sequences

Escape sequence Description Example Output
\n New line print("Hello\nWorld") Hello
\t Horizontal tab print("Hello\tWorld") Hello    World
\' Single quote print("Hello \'World\' ") Hello 'World'
\" Double quote print("Hello \"World\" ") Hello "World"
\\ Backslash print("Hello \\World") Hello \World

Topics You Might Like