You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The way I understand what I think you are asking is that this isn't a bug at all.
Python will interpret 3--2 as 3 - (-2) subtracting a negative is the same as adding the positive. So this expression evaluates to 3+2. 3++2 evaluates to the exact same thing 3+(+2) or 3+2. so as you can see both are equal to 5
There's already an example in the minor ones section along the similar lines
Given that a is a number, ++a and --a are both valid Python statements but don't behave the same way as compared with similar statements in languages like C, C++, or Java.
>>> a = 5
>>> a
5
>>> ++a
5
>>> --a
5
💡 Explanation:
There is no ++ operator in Python grammar. It is actually two + operators.
++a parses as +(+a) which translates to a. Similarly, the output of the statement --a can be justified.
This StackOverflow thread discusses the rationale behind the absence of increment and decrement operators in Python.
The text was updated successfully, but these errors were encountered: