On Dec 8, 7:58 pm, Karthik Gurusamy <[EMAIL PROTECTED]> wrote: > 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
There is a unary operator "+". When you write ++n, it's evaluating +n, and then +(that result). -- http://mail.python.org/mailman/listinfo/python-list