Categories: Programming Python Python Basic Tutorial

Python Escape Sequence List and Uses

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.

Related Post

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('6')
6
>>> 

List of Escapes Sequences

Escape SequenceCharacter representedExampleOutput
\aAlertprint(‘\a‘)NA
\bBackspaceprint(‘pyc’ + ‘\b‘ + ‘thon’)python
\\Back Slashprint(‘\\‘)\
\’Single Quoteprint(‘\’‘)
\”Double Quoteprint(‘\”‘)
\nPage Line Feed (New Line)print(“Hello\nWorld”)Hello
World
\tHorizontal tabprint(“Hello\tWorld”)Hello    World
\uhhhhPrints 16-bit hex value Unicode characterprint(“\u0041”)A
\UhhhhhhhhPrints 32-bit hex value Unicode characterprint(“\U00000041”)A
\oooPrints character based on its octal numberprint(“\066”)6
\xhhPrints character based on its hex valueprint(“\x23”)#
PyBlog.in
Aditya Kumar

Share
Tags: Programming Python Python Basic Tutorial

Recent Posts

  • Programming

Mastering Print Formatting in Python: A Comprehensive Guide

In Python, the print() function is a fundamental tool for displaying output. While printing simple…

8 months ago
  • Programming

Global Variables in Python: Understanding Usage and Best Practices

Python is a versatile programming language known for its simplicity and flexibility. When working on…

8 months ago
  • Programming

Secure Your Documents: Encrypting PDF Files Using Python

PDF (Portable Document Format) files are commonly used for sharing documents due to their consistent…

8 months ago
  • Programming

Creating and Modifying PDF Files in Python: A Comprehensive Guide with Code Examples

PDF (Portable Document Format) files are widely used for document exchange due to their consistent…

8 months ago
  • Programming

Boosting Python Performance with Cython: Optimizing Prime Number Detection

Python is a high-level programming language known for its simplicity and ease of use. However,…

8 months ago
  • Programming

Using OOP, Iterator, Generator, and Closure in Python to implement common design patterns

Object-Oriented Programming (OOP), iterators, generators, and closures are powerful concepts in Python that can be…

8 months ago

This website uses cookies.