[Python-ideas] Making colons optional?

Steven D'Aprano steve at pearwood.info
Thu Feb 5 12:01:21 CET 2009

Riobard Zhan wrote:

> - I noticed a strong tendency to forget colons by new users of Python in 
> a second-year computer science undergraduate course. The students seemed 
> not getting used to colons even near the end of the course. I guess it 
> is probably because they learn Java and C first, both of which do not 
> have colons. What other languages do you know that require colons? 

Pascal uses colons, but not for the exact same purpose as Python. Both 
languages use colons in similar ways to it's use in English. In 
particular, Python uses colons as a break between clauses: larger than a 
comma, smaller than a period.

> - I find colons pretty annoying. 

I'm sorry you dislike colons, but I like them.

> What do you think? Specifically, may I ask your feedback on the 
> following issues?
> - Do you find yourself sometimes forget to type them and the interpreter 
> complains?

Perhaps one time in 1000, MUCH less often than I miss a closing 
parenthesis, and about as often as I accidentally use round brackets 
instead of square (or visa versa).

> - Are the above pieces of code less readable due to lack of colons?

I think so.

I came to Python from Pascal and Hypertalk, two very different 
languages. I never missed Pascal's semi-colons at the end of each line, 
and Hypertalk rarely use punctuation (other than for arithmetic). I 
didn't find it difficult to pick up on using colons.

As an exercise, I just took a look at some old Hypertalk code, and found 
the lack of colons equally distracting in it as I find it in your examples.

> - What problems do you think will occur if colons are made optional?

I don't think it would lead to any problems, but I think it would make 
Python less elegant.


More information about the Python-ideas mailing list