![]() |
VOOZH | about |
Python does not include the ++ and -- operators that are common in languages like C, C++, and Java. In this article, we will see why Python does not include these operators and how you can achieve similar functionality using Pythonic alternatives.
Python is not just about writing code it’s about writing code that is clear, readable and less error-prone.
In many programming languages, shorthand operators like ++ and -- may save a few keystrokes, but they can also introduce confusion when used inside complex expressions.
Instead of this:
i = 5;
j = ++i * 2; // Prefix increment, increases first then multiplies
k = i++ * 2; // Postfix increment, multiplies first then increases
You often need to remember whether increment happens before or after the expression. This can easily lead to mistakes. Python avoids this confusion entirely by not having ++ and -- at all.
Here are the main reasons behind this design decision:
In Python, explicit += and -= operators are the official and Pythonic way to increment or decrement values.
6 9
Let’s test it:
Python interprets x++ as +(+x), meaning just apply unary plus twice. The value remains unchanged. This confuses beginners even more, which is why it’s better to stick to x += 1.