🔵 🔵 🔵


Primary

၊၊||၊|။

r'...' ⚬ᵖʸ|Definition|1st|20251021004502-00-⌔

2. Lexical analysis — Python 3.14.2 documentation#raw-string-literals

2.5.6. Raw string literals

Both string and bytes literals may optionally be prefixed with a letter ‘ r ’ or ‘ R ’; such constructs are called raw string literals and raw bytes literals respectively and treat backslashes as literal characters. As a result, in raw string literals, escape sequences are not treated specially:

>>> r'\d{4}-\d{2}-\d{2}'
'\\d{4}-\\d{2}-\\d{2}'

Even in a raw literal, quotes can be escaped with a backslash, but the backslash remains in the result; for example, r"\"" is a valid string literal consisting of two characters: a backslash and a double quote; r"\" is not a valid string literal (even a raw string cannot end in an odd number of backslashes). Specifically, a raw literal cannot end in a single backslash (since the backslash would escape the following quote character). Note also that a single backslash followed by a newline is interpreted as those two characters as part of the literal, not as a line continuation.

Printed 2026-06-28.

(echo:: @ )

Link to original

Secondary

• • •