What is behavior of ++ and -- operators in Python?

PythonServer Side ProgrammingProgramming

In C/C++ and Java etc, ++ and -- operators are defined as increment and decrement operators. In Python they are not defined as operators.

In Python objects are stored in memory. Variables are just the labels. Numeric objects are immutable. Hence they can't be incremented or decremented.

However, prefix ++ or -- doesn't give error but doesn't perform either.

>>> a=5
>>> b=6
>>> ++a
>>> --b

Postfix ++ or -- produce errors

>>> a=5
>>> b=6
>>> a++
SyntaxError: invalid syntax
>>> b--
SyntaxError: invalid syntax
Published on 12-Feb-2018 09:30:29