Escape Sequences in Python

Introduction

Escape sequences are special characters used inside string literals to represent certain whitespace, formatting, or control characters that are otherwise difficult to include directly in a string. They begin with a backslash (\\) followed by a character or sequence that specifies the desired special behavior.

Escape sequences allow us to:

Common Escape Sequences

In this chapter, we will explore the following escape sequences in Python:

Each of these will be covered in detail with examples in the following pages.