Description
Escape sequences are the sequence of characters that is translated into other characters or a sequence of characters that are difficult to represent directly.
All the escape sequences contain more than one character. They all start with a backslash ‘\’ also called Escape Character. Escape sequences are generally used in String. You can check out our latest tutorial on Python Strings to know more about it.
Example
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> print('Hello\nWorld') Hello World >>> print('Hello\tWorld') Hello World >>> print('I\'m backslash - \\') I'm backslash - \ >>> print('\066') 6 >>>
List of Escapes Sequences
Escape Sequence | Character represented | Example | Output |
\a | Alert | print(‘\a‘) | NA |
\b | Backspace | print(‘pyc’ + ‘\b‘ + ‘thon’) | python |
\\ | Back Slash | print(‘\\‘) | \ |
\’ | Single Quote | print(‘\’‘) | ‘ |
\” | Double Quote | print(‘\”‘) | “ |
\n | Page Line Feed (New Line) | print(“Hello\nWorld”) | Hello World |
\t | Horizontal tab | print(“Hello\tWorld”) | Hello World |
\uhhhh | Prints 16-bit hex value Unicode character | print(“\u0041”) | A |
\Uhhhhhhhh | Prints 32-bit hex value Unicode character | print(“\U00000041”) | A |
\ooo | Prints character based on its octal number | print(“\066”) | 6 |
\xhh | Prints character based on its hex value | print(“\x23”) | # |
PyBlog.in |