How do you split long line to multiple lines in Python?

Experience Level: Junior
Tags: Python

Answer

To break a long line to multiple lines, use a backslash character at the end of a line.

Example:

def do_something():
    message = "This is" \
                       "multi-line" \
                       "message"

Python for beginners
Python for beginners

Are you learning Python ? Try our test we designed to help you progress faster.

Test yourself