Lesson 7: All the arithmetic operators
Seven operators do all the arithmetic in Python: add, subtract, multiply, divide, floor divide, remainder and power. One short program shows each one, plus the…
Blog
29 lessons, in order — start at lesson 1 and work down.
Seven operators do all the arithmetic in Python: add, subtract, multiply, divide, floor divide, remainder and power. One short program shows each one, plus the…
The equals sign stores a value. The shorthand forms such as += add first and store after, so total += 25 means total = total + 25. One program walks through every…
Comparison operators ask a question and answer True or False. Logical operators join those answers with and, or and not. One program shows all of them, including a…
Bitwise operators work on the individual bits of a number, not on the number as a whole. Six of them — and, or, xor, not, shift left and shift right — with 5 and 3…
Membership asks whether a value is inside a collection. Identity asks whether two names point at the same object. They look similar and answer completely different…
When one expression holds several operators, Python applies them in a fixed order: power first, brackets above everything. These are the rules, with the three cases…