# How to wrap long lines in Python?

PythonServer Side ProgrammingProgramming

The preferred way of wrapping long lines is by using Python's implied line continuation inside parentheses, brackets and braces. If necessary, you can add an extra pair of parentheses around an expression, but sometimes using a backslash looks better. Make sure to indent the continued line appropriately. The preferred place to break around a binary operator is after the operator, not before it.

Example of paranthesized line break:

 list(
"Hello"
)

This will give the output:

['H', 'e','l', 'l', 'o']

Example of back-slashed line break:

 print 'This s a really long line,', \
'but we can make it across multiple lines.'

This will give the output:

This is a really long line, but we can make it across multiple lines.

Both of these can be used, you may choose to use either depending on which looks more readable to you.

Updated on 30-Sep-2019 08:29:05