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.
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.