auto-increment operator - why no syntax error?
Karthik Gurusamy
kar1107 at gmail.com
Sat Dec 8 19:58:25 EST 2007
I see python doesn't have ++ or -- operators unlike say, C.
I read some reasonings talking about immutable scalars and using ++/--
doesn't make much sense in python (not sure if ++i is that far-fetched
compared to the allowed i += 1)
In any case, I accidentally wrote ++n in python and it silently
accepted the expression and it took me a while to debug the problem.
Why are the following accepted even without a warning about syntax
error?
(I would expect the python grammar should catch these kind of syntax
errors)
>>> n = 1
>>> 2 * +++++ n
2
>>> n += 1
>>> n
2
>>> ++n
2
Karthik
More information about the Python-list
mailing list