Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I've always laughed to myself when I've looked back at my VB6 days and thought, "What modern language doesn't allow incrementing with double plus signs?":

number++

To my surprise, I can't find anything about this in the Python docs. Must I really subject myself to number = number + 1? Don't people use the ++/-- notation?

1 Answer

0 votes
by (106k points)
edited by

Python does not support ++ like other languages because once you do ++/-- it becomes a statement, not an operator. In Python, all the namespace modification is in a statement. That's one of the design decisions. And also because integers are immutable, the only way to 'change' a variable is by re-assigning it.

To get the value of ++/-- you can work with the following way:-

number += 1 and number -= 1

Learn more about Python from an expert. Enroll in our Python Course! 

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...