A Suggestion for Python Colon Syntax

Tim Peters tim.one at home.com
Thu Dec 21 12:52:37 EST 2000


[William Djaja Tjokroaminata]
> ...
> 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?  Because Python is line-and-indentation-based, can we just
> eliminate the colons after the if, for, etc., clause?

Python's indentation rules are inherited from the ABC language (Guido was a
member of the ABC implementation team).  The ABC designers tried several
styles of denoting block structure, and ran usability studies with newbies
to determine which were easiest to learn.

Guido reported that indentation worked best in these studies, but--
curiously enough! --only if the line immediately preceding the new block
ended with a colon.  And that's why Python requires the colon too:  it's not
because the parser needs it, but because a study once concluded *people* do
better with it.

> 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):
                                                ^
> ...

Also curious:  you never forget the colon at the ends of your introductory
sentences <wink>.

without-a-colon-life-itself-is-impossible-ly y'rs  - tim






More information about the Python-list mailing list