Why aren't colons optional?

Hans Nowak wurmy at earthlink.net
Sat Jan 19 20:07:40 EST 2002


"Edward K. Ream" wrote:
> 
> Hi all,
> 
> Why are colons required after def, elif, else, except, finally, for, if,
> try and while?  One would think the colon would be optional when the
> colon is followed by a newline.
> 
> Obviously, colons are required in:
                                   ^
> 
>   if a == 1 : b = c
>   elif a == 2 : b = d
>   else : b = e
> 
> My question is: why isn't the following valid?
                ^

Note the colons in your own post. :-)  They are not really
necessary for understanding what you wrote, but they make
the sentence easier to read. Same with Python. The colon
is not necessary for parsing if it's followed by a code
block, but it increases readability. It's there for
human readers.

--Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==') 
       # decode for email address ;-)
Site:: http://www.awaretek.com/nowak/



More information about the Python-list mailing list