@@ -317,3 +317,40 @@ values in before you return
317317
318318 square, cube = math_func(3 )
319319
320+ Line Continuations
321+ ~~~~~~~~~~~~~~~~~~
322+
323+ When a logical line of code is longer than the accepted limit, you need to split it over multiple
324+ physical lines. Python interpreter will join consecutive lines if the last character of the line is
325+ a backslash. This is helpful sometime but is preferably avoided, because of its fragility: a white
326+ space added to the end of the line, after the backslash, will break the code and may have unexpected
327+ results.
328+
329+ A prefered solution is to use parenthesis around your elements. Left with an unclosed parenthesis on an end-of-line
330+ the Python interpreter will join the next line until the parenthesis is closed. The same behavior holds for
331+ curly and square braces.
332+
333+ **Bad **:
334+
335+ .. code-block :: python
336+
337+ my_very_big_string = """ For a long time I used to go to bed early. Sometimes, \
338+ when I had put out my candle, my eyes would close so quickly that I had not even \
339+ time to say “I’m going to sleep.”"""
340+
341+ from some.deep.module.inside.a.module import a_nice_function, another_nice_function, \
342+ yet_another_nice_functio
343+
344+ **Good **:
345+
346+ .. code-block :: python
347+
348+ my_very_big_string = (" For a long time I used to go to bed early. Sometimes, "
349+ " when I had put out my candle, my eyes would close so quickly that I had not even "
350+ time to say “I’m going to sleep.”" )
351+
352+ from some.deep.module.inside.a.module import (a_nice_function, another_nice_function,
353+ yet_another_nice_functio)
354+
355+ However, more often than not having to split long logical line is a sign that you
356+ are trying to do too many things at the same time, which may hinder readability.
0 commit comments