- +=
- -=
- **
- ++
- --
- %
- /
- //
Operators for Numbers
examples/numbers/operators.py
a = 2 b = 3 c = 2.3 d = a + b print(d) # 5 print(a + b) # 5 print(a + c) # 4.3 print(b / a) # 1.5 # see the __future__ print(b // a) # 1 # floor division print(a * c) # 4.6 print(a ** b) # 8 (power) print(17 % 3) # 2 (modulus) a += 7 # is the same as a = a + 7 print(a) # 9 # a++ # SyntaxError: invalid syntax # a-- # SyntaxError: invalid syntax a += 1 print(a) # 10 a -= 1 print(a) # 9
There is no autoincrement (++) and autodecrement (--) in Python, because they can be expressed by += 1 and -= 1 respectively.