views:

311

answers:

2

It seems to be ignored inside a list, for example:

for x in range(5):
    list += [x, 1
,2,3,

     4,5]
+13  A: 

White-space is only important for indentation of statements, what you have is a single statement across several lines, only the indentation of the beginning of the statement on the first line is significant, see this for more info.

Robert Gamble
+7  A: 

Your question is really about when Python implicitly joins lines of code.

Python will implicitly join lines that are contained within (parentheses), {braces}, and [brackets], as in your example code. You can also explicitly join lines with a backslash (\) at the end of a line.

More here on implicit line continuation:

Mr. Gamble's answer is correct for indentation.

Triptych