n++ < 10 syntax error??

Chris Liechti cliechti at gmx.net
Sun Jan 13 11:51:57 EST 2002

rihad <rihad at mail.ru> wrote in 
news:h7d34ucusarslbdqfhiu2bvsph2lg9bf5t at 4ax.com:
> Hi there, continuing with my foray into the innards of Python, I found
> myself stumbled over this:
> n = 0
> while n++ < 10:
>   pass
> Gives a syntax error. Changing n++ to ++n compiles fine.... What the
> hell is going on???
> (P.S. I know I can use the "for n in range(10)" idiom, but what's
> wrong with n++?)
there is no pre/post increment in python ++n applies the unary operator + 
(__pos__) twice...

newer versions of python support += etc.
while n<10: n+=1

i still prefer the for loop with range.

Chris <cliechti at gmx.net>

More information about the Python-list mailing list