--, Do ++

Asked 2 years ago, Updated 2 years ago, 69 views

There is no posterior operator in Python, but there is a potential operator? So I used it, but the price doesn't increase. Why doesn't Python support front and rear increments like C++?

a = 1
++a
print a

python increment decrement operator

2022-09-22 22:31

1 Answers

++ is not operator. It's just a combination of two + operator. As you know, there is no point in putting + in front of the int type variable.

in other words ++a = +(+a) = a This is.

If you want to calculate ++ and -- of C, Python requires +=1 and -=1.

Python is a language that values consistency and readability. This is not Python because ++ and -- can produce different results depending on the potential/post.

In addition, theoretically, ++ and -- operations are faster These days, the compiler optimizes the code on its own, so I don't think you need to pay much attention to the performance.


2022-09-22 22:31

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.