How to Split a Long String Over Several Lines in Python
A long message makes a line of code too wide to read. Python joins strings written right next to each other into one, so you can break the message into pieces inside brackets, one per line, and still get a single string. This guide shows how, with real output from Python 3.15.2.
Syntax
<name> = (
"<first piece> "
"<second piece>"
)
| Part | What it means |
|---|---|
( ... ) | Brackets let the expression continue over several lines |
"<first piece> " "<second piece>" | Strings with only spaces or line breaks between them become one string |
| The space at the end of a piece | Python adds nothing between the pieces, so the spaces are yours to place |
Python's language reference: "Multiple adjacent string or bytes literals, possibly using different quoting conventions, are allowed, and their meaning is the same as their concatenation". It adds: "This feature is defined at the syntactical level, so it only works with literals."
Prerequisites
- uv and Python. This guide uses uv 0.13.10 with Python 3.15.2, in a project made with
uv init.
Step 1: Write the Script
greeting = (
"Welcome to the shop. "
"Ask about shipping, returns or refunds."
)
print(greeting)
print("snow" "board")

Step 2: Run It
uv run python long_string.py
Welcome to the shop. Ask about shipping, returns or refunds.
snowboard

The two pieces of greeting became one line. "snow" "board" shows that Python adds nothing between the pieces: the space in the greeting comes from the end of "Welcome to the shop. ".
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
| Leaving out the space at the end of a piece | "Welcome to the shop." "Ask about shipping." prints Welcome to the shop.Ask about shipping. | End each piece with the space it needs |
Trying it with a variable, as in a "y" | SyntaxError: invalid syntax: it only works with literals | Use + or an f-string for variables |
| Forgetting a comma between list items | ["tent" "stove"] is one item, "tentstove" | Put commas between list items |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| A list has fewer items than written | Two strings without a comma were joined | Add the missing comma |
FAQ
Do I need the brackets?
Only when the pieces are on different lines. On one line, "snow" "board" works without them.
Is this better than +?
For literals, yes: Python joins them once, while reading the code. + joins at run time and is needed for variables.
Conclusion
Two strings written one under the other inside brackets printed as one sentence, and "snow" "board" printed snowboard, with no space added between the pieces.
Additional Resources
- String literal concatenation — adjacent literals and their limits.
