Ad space (banner)
🐍Python Lessons
Lesson 47 / 69

Multi-Line Strings (triple quotes)

This lesson covers writing multi-line strings with triple quotes, so you can build readable, well-formatted messages. It's written for anyone searching "Python multiline string tutorial".

Wrapping text in three double quotes lets you write a multi-line string that includes real line breaks. It's handy for writing something like an email body or a long explanation in a readable way. Add an f at the front, and you can combine it with f-string variable interpolation too.

The sample code builds a 3-line message using an f-prefixed triple-quoted string, with the variable name embedded inside. Written at the top of a function, this same syntax is also treated as a docstring (a function's description) — a nice two-for-one, since documentation tools will pick it up automatically as the function's description.

A common beginner mistake is not realizing that any indentation inside a multi-line string is included literally in the output. If you indent it to make the code more readable, that whitespace becomes part of the actual string, so the visual layout in your editor and the actual output can differ.

Because it can include line breaks and indentation exactly as written, it's well suited for assembling template-like text. Triple-quoted strings are put to work in all kinds of places involving multi-line text — email templates, report skeletons, and more.

Python
OUTPUT

💡 The Python engine may take a few seconds to load the first time you run code.

Ad space (banner)
Ad space (in-article)