Last Updated : 30 Jun, 2025
In Python, a statement (logical command or an instruction) usually ends at the end of a line. But sometimes, your code is too long and needs to be split into multiple lines to make it easier to read or write.
For Example:
Python
g = "geeks\
for\
geeks"
print(g)
Let's see different ways to use multi line statements in python.
Explicit line continuation - Using "\"backslash (\) is used to split a long line of code into multiple lines called as explicit line continuation. It tells Python that the statement continues on the next line, preventing a syntax error.
Python
txt = "A Computer Science portal\
for geeks"
print(txt)
r = 10 + \
20 - \
5
print(r)
A Computer Science portal for geeks 25
Explanation: uses \ to split a string and a math operation across multiple lines.
Implicit line continuation - Using (), [], and {}Implicit line continuation allows long statements to be split across multiple lines as long as the code is enclosed within parentheses ( ), brackets [ ], or braces { }.
Python
g = ("geeks"
"for"
"geeks")
print(g)
n = [1, 2,
3, 4]
print(n)
t = (50 +
40 -
52)
print(t)
geeksforgeeks [1, 2, 3, 4] 38
Explanation: uses (), [] and () to split a string, a list and a math expression across multiple lines.
Line break - Using triple quoteTriple quotes (""" """ or ''' ''') are used to create multi-line strings. When a string is enclosed within triple quotes, it can span multiple lines. It is useful for writing long text blocks, documentation strings (docstrings), or preserving line breaks exactly as written.
Python
g = """geeks
for
geeks"""
print(g)
Explanation: uses """ """ to create a multi-line string and prints it with line breaks included.
Related Article:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4