Python Increment & Decrement
In this page:
variable += 1 # increment
variable -= 1 # 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
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
score = 0
score += 10 # add 10 to score in one step
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
lives = 3
lives -= 1 # subtract 1 from lives in one step
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
scores = [10, 20, 30]
scores[0] += 5 # read and update the value at index 0 in place
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
value = 4
value *= 2 # scale value up
print(value)
value /= 4 # scale value down
print(value)
- Writing
x++or++x, which is not valid increment syntax;++xsilently does nothing (two unary plus signs) andx++is aSyntaxError; usex += 1. - Mixing types when incrementing, such as
count += "1"on an int, which raisesTypeError. - Modifying the loop variable in
for i in range(n): i += 1, expecting it to skip iterations;rangeresetsievery pass.
Chapter Quiz — Complete all 16 topics to unlock
0/16 topics done
Complete these topics first:
- Python print()
- Python input()
- Python Format Strings
- Python f-strings
- Python String Formatting
- Python Arithmetic Operators
- Python Relational Operators
- Python Logical Operators
- Python Bitwise Operators
- Python Assignment Operators
- Python Increment & Decrement
- Python Ternary Operator
- Python Operator Precedence
- Python Identity Operators
- Python Membership Operators
- Python Operators