n++ < 10 syntax error??

Alex Martelli aleax at aleax.it
Sun Jan 13 17:39:28 EST 2002


Tal Linzen wrote:

>> Python doesn't have the ++ autoincrement operator.  + is a unary operator
>> on a numeric arg, that does nothing.  ++n is the same as n.
> 
> Why is a construct like ++n or --n even allowed? I can't think of a
> context where it's useful,
> and it's evidently misleading for beginners with C background.

It's not worth hugely complicating a language's rules to forbid all 
(arithmetic and non-) operations that "can't be useful":
        + + x
        - - x
        x + 0
        0 + x
        x * 1
        1 * x
        x / 1
        x - x + x
and so on ad infinitum.

The language is substantially simpler because it does not try to forbid 
every construct that "can't be useful" and could be misleading to some 
beginner for a short while.  Simplicity trumps trying to second-guess the 
users or protect them from themselves -- at least, in Python.


Alex




More information about the Python-list mailing list