In this tutorial, I will explain how to continue long strings on the next line in Python. As a Python developer when working with lengthy strings in my Python code, I came across a scenario where I needed to break them up for better readability and maintainability. Then I explored more about this topic and I will share my findings in this article with examples and screenshots of executed example code.
Continue Long Strings on the Next Line in Python
Python provides several ways to continue a string on the next line without affecting the string’s content. Let us learn some important methods.
Read Convert Int to Bytes in Python
1. Use Parentheses to Split Long Strings
One common approach to continue a string over multiple lines in Python is by using parentheses. When you enclose a string within parentheses, you can freely add line breaks without disrupting the string’s integrity. Here’s an example:
name = "John Smith"
address = "123 Main St, New York, NY 10001"
message = (
f"Dear {name},\n"
f"Thank you for your recent purchase. "
f"Your order will be shipped to:\n"
f"{address}"
)
print(message)Output:
Dear John Smith,
Thank you for your recent purchase. Your order will be shipped to:
123 Main St, New York, NY 10001I have executed the above example code and added the screenshot below.

In this example, the message string is split across multiple lines using parentheses. The line breaks within the parentheses are ignored, and the string is treated as a single continuous string.
Read Convert DateTime to UNIX Timestamp in Python
2. Use Backslashes for Line Continuation
Another way to split a long string over multiple lines is by using the line continuation character, which is a backslash (\) at the end of each line. The backslash indicates that the string continues on the next line. Here’s an example:
customer_name = "Sarah Johnson"
email = "sarah.johnson@example.com"
subject = "Order Confirmation"
body = "Dear " + customer_name + ",\n" \
"We are pleased to inform you that your order has been confirmed. " \
"You will receive a shipping confirmation email once your order is dispatched.\n" \
"If you have any questions, please reply to this email: " + email + ".\n" \
"Best regards,\n" \
"The Sales Team"
print(f"Subject: {subject}\n\n{body}")Output:
Subject: Order Confirmation
Dear Sarah Johnson,
We are pleased to inform you that your order has been confirmed. You will receive a shipping confirmation email once your order is dispatched.
If you have any questions, please reply to this email: sarah.johnson@example.com.
Best regards,
The Sales TeamI have executed the above example code and added the screenshot below.

In this example, the body string is split into multiple lines using backslashes. The backslash at the end of each line indicates that the string continues on the next line.
Read Concatenate String and Float in Python
3. Use Triple Quotes for Multiline Strings
Python also supports multiline strings using triple quotes (either single quotes ''' or double quotes """). Triple quotes allow you to write a string that spans multiple lines without the need for explicit line continuation characters. Here’s an example:
disclaimer = '''
DISCLAIMER:
The information provided in this email is for general informational purposes only.
It is not intended as a substitute for professional advice.
If you have specific questions or concerns, please consult with a qualified professional.
'''
print(disclaimer)Output:
DISCLAIMER:
The information provided in this email is for general informational purposes only.
It is not intended as a substitute for professional advice.
If you have specific questions or concerns, please consult with a qualified professional.I have executed the above example code and added the screenshot below.

In this example, the disclaimer string is defined using triple single quotes. The string spans multiple lines, and the line breaks are preserved in the output above.
Read How to Find the Largest and Smallest Numbers in Python?
Conclusion
In this tutorial, we how to continue long strings on the next line in Python. We learned how to use parentheses to split long strings , how to use backslashes for line continuation , and triple quotes for multiline strings. These techniques help improve the readability and maintainability of your Python code when dealing with lengthy strings.
You may also like to read:
- How to Check if a Python String Contains a Substring?
- How to Reverse a String in Python?
- Find the First Number in a String in Python

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.