How does ++ and -- operators work in Python?

PythonServer Side ProgrammingProgramming

In C, C++, Java etc ++ and -- operators increment and decrement value of a variable by 1. In Python these operators won't work. 

In Python variables are just labels to objects in memory. In Python numeric objects are immutable. Hence by a++ (if a=10) we are trying to increment value of 10 object to 11 which is not allowed.

>>> a=10
>>> a++
SyntaxError: invalid syntax

Instead we have to use += operator

>>> a=a+1
>>> a
Updated on 26-Feb-2020 07:33:18