A Suggestion for Python Colon Syntax

Fredrik Lundh fredrik at effbot.org
Thu Dec 21 12:26:14 EST 2000


"William Djaja Tjokroaminata" wrote:
> However, a lot of time when I ran my Python program, I got syntax
> error, because I forgot to put colon (:) after my if (or for, etc.) clause.
> My question is, is the colon really necessary, syntactically, in Python?

Short answer:  The colon isn't there for the computer, it's
there for human readers.  Just like the colons in your post:

> My suggestion is as follows:
>
> 1) If the if (or for, etc.) clause is followed by a block, then the colon
> is optional (for backward compatibility):
>
>    if condition is true
>        statement_1
>        statement_2
>        ....

(Using colons and indentations in the same way as in other written
languages is just one of many ideas Python has borrowed from the
ABC language: http://www.cwi.nl/~steven/abc )

:::

Longer answer: ... nah, I'll leave that to the "while true" crowd.
I'm sure they'll keep you entertained until the end of next year!

:::

Happy holidays, everyone!

</F>





More information about the Python-list mailing list