[Tutor] Colons

alan.gauld@bt.com alan.gauld@bt.com
Fri Mar 28 13:27:01 2003


> Can someone explain the design philosophy behind certain 
> statements, namely function definitions and control statements, 
> requiring colons?  

I agree, it's strange on first sighting. I certainly didn't 
understand it when I started.

Basically the colon tells Python that what follows is the block 
of code to be executed as the function or control structure.

The idea is it looks like the use of a colon in English grammar.
Apparently its something that comes from Pythons ABC heritage 
where some research showed that absolute beginning students 
found the colon helpful in comprehending the code

Its useful IMHO for single line statements like:

if foo != bar: print bar

But if you always use an indented newline like

if foo != bar:
    print bar

then it's not so useful IMHO.

Alan G