syntax – Python integer incrementing with ++

syntax – Python integer incrementing with ++

Python doesnt support ++, but you can do:

number += 1

Simply put, the ++ and -- operators dont exist in Python because they wouldnt be operators, they would have to be statements. All namespace modification in Python is a statement, for simplicity and consistency. Thats one of the design decisions. And because integers are immutable, the only way to change a variable is by reassigning it.

Fortunately we have wonderful tools for the use-cases of ++ and -- in other languages, like enumerate() and itertools.count().

syntax – Python integer incrementing with ++

You can do:

number += 1

Leave a Reply

Your email address will not be published.