Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
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)

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

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...