StudyToCert

All certifications / PCEP / Lessons

PCEP – Certified Entry-Level Python Programmer PCEP-30-02 · Domain 3: Data collections: tuples, dictionaries, lists and strings

Escaping with \, quotes and apostrophes inside strings, multi-line strings

▶ Watch the overview video

Last reviewed September 30, 2026 · Leer en español

A string literal is text in your source code delimited by quotes, so putting quote characters inside it needs care: Python has to know which quote ends the string. Python gives you two easy ways out. First, choose the other kind of quote for the delimiters: "It's fine" contains an apostrophe inside double quotes, and 'She said "hi"' contains double quotes inside single quotes. Single and double quotes are otherwise identical in Python; neither is "more correct". Second, escape the quote with a backslash: 'It\'s fine' and "She said \"hi\"" are both valid and produce the same text.

Free account

Keep reading for free

Create a free StudyToCert account to read the rest of this lesson: 7 more sections, 6 key terms, a real-world example, an exam tip and self-check questions. Every lesson, lab and practice test is free with an account.

Sign up free Log in

Study PCEP for free
A week-by-week plan with every lesson, quizzes, checkpoint tests, a practice exam and hands-on labs.
Open the PCEP study plan