In this tutorial, I will explain how to split a long string into multiple lines in Python. As a software developer working on a report generation tool, I encountered a scenario where long strings needed to fit within fixed-width columns for better readability. Then, I researched methods to split long strings into multiple lines while maintaining word boundaries. I will share my findings in this article with examples.
Split a Long String into Multiple Lines in Python
Let us see some important methods to split a long string into multiple lines in Python.
Read How to Insert a Python Variable into a String?
1. Use Parentheses, Brackets, or Braces
In Python, you can freely break lines inside parentheses (), square brackets [], or curly braces {} without using a backslash. This rule allows you to split a long string into multiple lines seamlessly. Here’s an example:
long_string = (
"John Doe\n"
"123 Main Street\n"
"New York, NY 10001\n"
"United States"
)
print(long_string)Output:
John Doe
123 Main Street
New York, NY 10001
United StatesI have executed the above example code and added the screenshot below.

As you can see, the string is defined across multiple lines using parentheses, and Python automatically concatenates them into a single string.
Read How to Split a String by Index in Python?
2. Use Triple Quotes
Python supports multi-line strings by enclosing them in triple quotes, either """ or '''. This approach is particularly useful when dealing with long strings that span multiple lines. Here’s an example:
long_string = """
SELECT *
FROM customers
WHERE country = 'United States'
ORDER BY last_name ASC;
"""
print(long_string)Output:
SELECT *
FROM customers
WHERE country = 'United States'
ORDER BY last_name ASC;I have executed the above example code and added the screenshot below.

Triple quotes allow you to preserve the line breaks and indentation in the string, making it ideal for SQL queries or multi-line text.
Read Convert Binary to Decimal in Python
3. Use Backslashes
Another way to split a long Python string into multiple lines is by using backslashes \. By placing a backslash at the end of each line, you can indicate that the string continues on the next line. Here’s an example:
long_string = "Emily Johnson\n" \
"456 Elm Street\n" \
"Chicago, IL 60601\n" \
"United States"
print(long_string)Output:
Emily Johnson
456 Elm Street
Chicago, IL 60601
United StatesI have executed the above example code and added the screenshot below.

The backslash approach is useful when you want to split a string without adding extra indentation or when using parentheses or brackets is not convenient.
Read How to Split a String Every N Characters in Python?
4. Use the splitlines() Method
Python provides a built-in string method called splitlines() that allows you to split a multi-line string into a list of individual line sources. Here’s an example:
long_string = """
Michael Brown
789 Oak Avenue
Los Angeles, CA 90001
United States
"""
lines = long_string.splitlines()
for line in lines:
print(line)Output:
Michael Brown
789 Oak Avenue
Los Angeles, CA 90001
United StatesThe splitlines() method is handy when you need to process each line of a multi-line string separately.
Read Python Split Regex
Conclusion
In this tutorial, I explained how to split a long string into multiple lines in Python. I discussed some methods like using parentheses, brackets, or braces, triple quotes, backslashes, splitlines() method.
You may also like to read:
- How to Split a Sentence into Words in Python?
- How to Split a String and Get the Last Element in Python?
- How to Split a String into an Array 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.