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.
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('6') 6 >>>
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 |
In Python, the print() function is a fundamental tool for displaying output. While printing simple…
Python is a versatile programming language known for its simplicity and flexibility. When working on…
PDF (Portable Document Format) files are commonly used for sharing documents due to their consistent…
PDF (Portable Document Format) files are widely used for document exchange due to their consistent…
Python is a high-level programming language known for its simplicity and ease of use. However,…
Object-Oriented Programming (OOP), iterators, generators, and closures are powerful concepts in Python that can be…
This website uses cookies.