0 votes
1 view
in Python by (12.2k points)

I notice that a pre-increment/decrement operator can be applied on a variable (like ++count). It compiles, but it does not actually change the value of the variable!

What is the behavior of the pre-increment/decrement operators (++/--) in Python?

Why does Python deviate from the behavior of these operators seen in C/C++?

1 Answer

0 votes
by (24.2k points)

It is true that python does not have any increment or decrement operator like ++value etc, unlike languages like c++, java etc. This is because in python integers are immutable that is once declared they cannot be changed. If you wish to change the value of a variable holding integer value, you would need to reassign it. For example:

Instead of:

val = 10


You have to do it like this:

val = 10

val += 10 # Same as val = val + 10

To learn more about Python in depth you can watch this video on YouTube:

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers !