Why aren't colons optional?

John Roth johnroth at ameritech.net
Mon Jan 21 16:25:13 CET 2002


"Edward K. Ream" <edream at tds.net> wrote in message
news:3C49FED0.8C0F254E at tds.net...
> 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

Not true. If you eliminated colons, then those
examples would have to be written with semi-colons.

> My question is: why isn't the following valid?
>
>   if a == 1
>     b = c
>   elif a == 2
>     b = d
>   else
>     b = e

I'll have to agree with a number of posters here. I am mildly
for the colons; they give me a slight visual clue on the right
side of the statement. It's nothing I couldn't work around,
but at this late date, I wouldn't change it.

Also, breaking large numbers of editing tools and/or
creating an optional bit of syntax just isn't on at this
point. I'd very strongly vote against such a proposal

John Roth

Colon the Conqueror, driven from the far northland
by his half-brother, Semi-Colon.
(from a 1951 parody of Conan the Conqueror)






More information about the Python-list mailing list