W3docs

How can I do a line break (line continuation) in Python?

In Python, you can use the "" character to indicate a line continuation.

In Python, you can use the \ character to indicate a line continuation. For example:

Using the backslash () for line continuation

python— editable, runs on the server

You can also use parentheses, brackets, or braces to indicate a line continuation. For example:

Implicit line continuation with parentheses, brackets, or braces

python— editable, runs on the server

<div class="alert alert-info flex not-prose"> Watch a course <span class="hidden md:block">Watch a video course </span> Python - The Practical Guide</div>

You can also separate multiple statements on a single line using a semicolon (;). Note that this acts as a statement separator, not a line continuation operator, and does not join lines into a single logical statement.

Separating multiple statements on one line

python— editable, runs on the server

For multi-line strings, you can use triple quotes (""" or '''). This preserves line breaks within the string literal rather than serving as a general code continuation method.

Creating multi-line strings with triple quotes

python— editable, runs on the server