[Python-ideas] Reducing colon uses to increase readability

Terry Reedy tjreedy at udel.edu
Mon Jun 30 06:01:01 CEST 2008

Andre Roberge wrote:

> In Python, the humble colon (:) has multiples uses:
> 1. as a signal to indentation increase, signaling a block of code,
> 2. in slices [a:b:c]
> 3. in dict assignments {a:b}
> 4. in lambda assignments  (lambda x: x+1)
> I would argue that, in these last three examples, there might be better choices.

It is a bit late in Python's career to make such changes, which would 
break nearly all substantial programs for at best a small visual gain.

-> is slightly harder to type than : and to me uglier.

Any new use of ';' has to neither conflict with its current use nor 
introduce ambiguities that would push Python out of its current LL(1) (I 
believe it is) grammar class.

'key: item' comports with 'keyword-or-phrase: explanation' constructions 
in English.

lambda expressions abbreviate def statements:
def name(args): return expression => lambda args: expression
The ':' separates header and body in both.

I agree that slices could have used something else, but....

don't hold your breath for a code-breaking change now.

Terry Jan Reedy

More information about the Python-ideas mailing list