I have a long line of code that I want to break up among multiple lines. What do I use and what is the syntax?
For example, adding a bunch of strings,
e = 'a' + 'b' + 'c' + 'd'
and have it in two lines like this:
e = 'a' + 'b' +
'c' + 'd'
I have a long line of code that I want to break up among multiple lines. What do I use and what is the syntax?
For example, adding a bunch of strings,
e = 'a' + 'b' + 'c' + 'd'
and have it in two lines like this:
e = 'a' + 'b' +
'c' + 'd'
From Style Guide for Python Code:
EDIT: PEP8 now recommends the opposite convention (for breaking at binary operations) used by Mathematicians and their publishers to improve readability.
Donald Knuth's style of breaking before a binary operator aligns operators vertically, thus reducing the eye's workload when determining which items are added and subtracted.
From PEP8: Should a line break before or after a binary operator?:
[3]: Donald Knuth's The TeXBook, pages 195 and 196
You can break lines in between parenthesises and braces. Additionally, you can append the backslash character
\
to a line to explicitly break it: