[Python-ideas] Making colons optional?

Steven D'Aprano steve at pearwood.info
Sat Feb 7 01:30:38 CET 2009

Riobard Zhan wrote:

> It is pretty clear that colon-supporters do not pay attention to the 
> inconsistency of semicolons being optional and colons being mandatory 

No, it is pretty clear that you do not understand the fundamental 
difference in semantics between colons and semi-colons. It is not an 

Colons are used as an indicator of *association*: the block following 
the colon is strongly associated with the line containing the colon, 
just like in English. This reinforces the association due to 
indentation, and makes it more obvious in complicated cases:

if (some very complicated
     statement) or (another big
     statement which goes over
     many lines) or clause:
     do something here
     do something else

Semi-colons are used as a *separator*, and they are designed for 
one-liners. They are permitted in multi-line programs only because there 
is no need to bother forbidding them, but they are completely redundant 
if followed by a line break instead of another statement.

x = 1; y = 2  # the semi-colon is useful

x = 1;
y = 2  # the semi-colon is useless line noise

Because colons are used for a very different thing than semi-colons, any 
inconsistency between the rules for one and the rules for the other is 
imaginary. Different purposes, different rules.


More information about the Python-ideas mailing list