An interesting beginner question: why we need colon at all in the python language?

Thorsten Kampe thorsten at thorstenkampe.de
Wed Jul 13 10:08:53 CEST 2011


* Thomas Jollans (Mon, 11 Jul 2011 16:16:17 +0200)
> Basically, it looks better, and is more readable. 

People tend to overlook the colon for the same reason they tend to 
forget to set the colon in the first place:
a) it's a very weak marker in comparison to indentation and
b) it looks like doubling the markup to them (colon plus indentation)

What makes the if syntax for me even more weird, is the fact that you 
can have an else clause with an else without a then clause with a then.

if x > 5:
    print whatever 
else:
    print whatever  

in comparison to:

if x > 5
then
    print whatever 
else
    print whatever 

> A colon, in English like in Python, means that something follows that
> is related to what was before the colon. So the colon makes it
> abundantly clear to the human reader that a block follows,

The block that follows makes it abundantly clear to the human reader 
that a block follows.

> and that that block is to be considered in relation to what was just
> said, before the colon.

The indentation makes it abundantly clear to the human reader that that 
indented block is to be considered in relation to what was just said, 
before the indentation.

Thorsten



More information about the Python-list mailing list