← Back to Python Course | Chapter 2: Input, Output & Operators | Lesson 11 of 16

Python Increment & Decrement

No ++ or -- in Python

Python deliberately has no ++ or -- operator — writing x++ is a syntax error, not a working statement with unexpected behavior. The idiomatic way to increase or decrease a variable is x += 1 or x -= 1 instead.

Example: No ++ or -- in Python

python
x = 5
# x++  # SyntaxError: invalid syntax
x += 1
print(x)

Incremental Addition

+= lets you add any amount, not just one, in a single step: score += 10 immediately updates score to reflect the new total without a separate addition and reassignment line.

Example: Incremental Addition

python
score = 0
score += 10
print(score)

Decremental Subtraction

-= mirrors += for subtraction, commonly used to count down remaining attempts, lives, or retries by decreasing a variable by a fixed or computed amount each time.

Example: Decremental Subtraction

python
lives = 3
lives -= 1
print(lives)

Incrementing List Items

To update a value stored inside a list, first access it by index and then apply the compound operator directly to that indexed position, like scores[0] += 5, which reads and rewrites that single list slot in place.

Example: Incrementing List Items

python
scores = [10, 20, 30]
scores[0] += 5
print(scores)

Other Combined Assignments

The same compound pattern extends to multiplication and division — *= scales a variable up and /= scales it down — giving Python a consistent shorthand family for "apply this operation, then store the result back."

Example: Other Combined Assignments

python
value = 4
value *= 2
print(value)
value /= 4
print(value)

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.