0 votes
1 view
in Python by (47.8k points)

Just like C, you can break a long line into multiple short lines. But in Python, if I do this, there will be an indent error... Is it possible?

1 Answer

0 votes
by (107k points)
selected by
Best answer

Yes, It is possible to break a long line to multiple lines in Python. The preferred way is by using Python's implied line continuation inside parentheses, brackets and braces.

You can add an extra pair of parentheses around an expression if it is necessary, but sometimes using a backslash looks better. Also, make sure to indent the continued line appropriately.

An example that illustrates how to do implicit line continuation:

a = some_function(

    '1' + '2' + '3' - '4')

 watch this YouTube tutorial on Python:

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers !