Blocks and Indentation
Statements that end with a ‘
:’ introduce a block
Blocks are indented
End of a block is end of indentation
No explicit block delimiters (like ‘
Indentation is not only Coding Style, but also Syntax*
Careful, you experienced programmers!
New bug type: Indentation Bug
i = 0 while i < 42: print('Still not an answer: '+str(i)) i = i+1 print('The answer is: '+str(i))
Keep in mind …
Indentation must be consistent within one block
… can be mixed otherwise
Tune your editor’s knobs accordingly!
Newline ends a statement …
answer = 42
Except … Multiline statements
answer = str(42) + \ ', but only most of the time'
print( "Hello", "World")
message = [ "Hello", "World"]
message = ( "Hello " + "World")