Why do we use triple quotes?


  1. Why do we use triple quotes?
  2. What are triple double quotes?
  3. Why does string literals have three quotes?

Why do we use triple quotes?

Spanning strings over multiple lines can be done using python’s triple quotes. It can also be used for long comments in code. Special characters like TABs, verbatim or NEWLINEs can also be used within the triple quotes. As the name suggests its syntax consists of three consecutive single or double-quotes.

What are triple double quotes?

To create strings that span multiple lines, triple single quotes ”’ or triple double quotes “”” are used to enclose the string. ”’ This string is on multiple lines within three single quotes on either side. ”’ “”” This string is on multiple lines within three double quotes on either side.

Why does string literals have three quotes?

String literals inside triple quotes, “”” or ”’, can span multiple lines of text. Python strings are “immutable” which means they cannot be changed after they are created (Java strings also use this immutable style). Since strings can’t be changed, we construct *new* strings as we go to represent computed values.