A Suggestion for Python Colon Syntax
William Djaja Tjokroaminata
billtj at y.glue.umd.edu
Thu Dec 21 12:43:29 EST 2000
Fredrik Lundh <fredrik at effbot.org> wrote:
: "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:
Well, the colons in my post is because I am writing in English. But
Python does not have semicolon etc, just to make it "pretty", but they do
have consequences if they are omitted. I personally don't see how the
colon help me more in distinguishing the clause from the body of the
clause when reading a Python code, because the indentation is supposed to
be the marker.
:> 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
: (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 )
Well, I don't know the rest of the people who use Python, but I
personally don't know anything about the ABC language. If a feature is
borrowed from C or Java or Perl, I think it is good. But a feature that
seems to add nothing from an obscure language to me is questionable.
: 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!
I am waiting, everyone....
: Happy holidays, everyone!
More information about the Python-list