Python - Block rule special case


Statements in a nested block of code are normally associated by being indented the same amount to the right.

The body of a compound statement can appear on the same line as the header in Python, after the colon:

if x > y: print(x) 

This allows us to code single-line if statements, single-line while and for loops, and so on.

This will work only if the body of the compound statement itself does not contain any compound statements.

Related Topic