How to use parenthesis (Implicit line continuation) In Python

In this type of multi-line statement, Implicit line continuation is used when you split a statement using either parenthesis ( ), brackets [ ], and braces { }. 

Example:

In this example, we are initializing the list and the mathematical expression using the parentheses ( ), brackets [ ], and braces { } sign which is the implicit line continuation to continue the same line in the multiple lines in python programming.

Python3




# Initializing a string
# using parentheis "()".
g = (f"geeks"
     f"for"
     f"geeks")
print(g)
 
# Initializing a list using the
# Implicit multi-line statement.
list = [5,
        4, 3, 2, 1
        ]
 
print()
print('Initializing a list using the\
 Implicit multi-line statement', list)
 
# Initializing a mathematical expression
# using the Implicit multi-line statement.
add = (50 +
       40 -
       52)
print()
print('Initializing a mathematical expression\
 using the Explicit multi-line statement', add)


Output:

w3wiki

Initializing a list using the Implicit multi-line statement [5, 4, 3, 2, 1]

Initializing a mathematical expression using the Explicit multi-line statement 38

Python – Multi-Line Statements

In this article, we are going to understand the concept of Multi-Line statements in the Python programming language.

Statements in Python:

In Python, a statement is a logical command that a Python interpreter can read and carry out. It might be an assignment statement or an expression in Python

Similar Reads

Multi-line Statement in Python:

In Python, the statements are usually written in a single line and the last character of these lines is newline. To extend the statement to one or more lines we can use braces {}, parentheses (), square [], semi-colon “;”, and continuation character slash “\”. we can use any of these according to our requirement in the code. With the line continuation character, we can explicitly divide a long statement into numerous lines (\)....

Using “\”(Explicit line continuation):

...

Using parenthesis (Implicit line continuation):

In this type of multi-line statement, we will be using the line continuation character (\) to split a statement into multiple lines....

Using triple quote(line break)

...