So many quotation marks?

Quick question. Why are there so many quotation marks (three sets!) in this example. See link below …

https://www.codecademy.com/courses/learn-python-3/lessons/string-methods/exercises/replace

I think I understand that one set of quotation marks refers to this being a string. But what are the other two sets for?

String literals inside triple quotes can span multiple lines of text. Because Python otherwise interprets whitespace (code indentation) as valid parts of code, this is helpful to be able to easily write multiple lines of some string.

So one set of quotations is to specify this being a string (sentence, for the lack of a better word?). The second set of quotations is to specify that we pressed the “return” key on our computer to get to the next line. And the third set of quotations is to specify that we pressed the “return” key yet again on our computer to get to the line below?

I don’t think so. I think that the three quotations just lets us write a long string on multiple lines of text and tell the Python compiler that this is all one string.

1 Like

So the three quotation marks come as a set unit? Instead of three units of individual quotation mark sets? Confused here!

I think when you use a single quotation set, it establishes a string. But because Python interprets whitespace, you have to use a set of three quotation marks to establish a string along multiple lines of text.

1 Like

https://docs.python.org/3/reference/lexical_analysis.html#strings


In plain English: Both types of literals can be enclosed in matching single quotes (' ) or double quotes (" ). They can also be enclosed in matching groups of three single or double quotes (these are generally referred to as triple-quoted strings ). The backslash (\ ) character is used to escape characters that otherwise have a special meaning, such as newline, backslash itself, or the quote character.

In triple-quoted literals, unescaped newlines and quotes are allowed (and are retained), except that three unescaped quotes in a row terminate the literal. (A “quote” is the character used to open the literal, i.e. either ' or " .)