Everything else is ready: study the parts, the key terms and the quiz below.
- Part 11Operators, operands and expressions
- Part 22The seven arithmetic operators, and the type each result has
- Part 33Floor division and modulo with negative numbers
- Part 44Precedence: which operator runs first, and the double star exception
- Part 55Comparison operators, chained comparisons, and assignment against comparison
- Part 66Logical operators: and, or, not, short circuit evaluation and returning an operand
- Part 77Augmented assignment: minus equals, plus equals, star equals and the rest
- Part 88Identity with is, and membership with in
- Part 99Why floats are not exact: isclose, storing cents, and rounding half to even
- Part 1010Recap and your challenge
Operators
Compute and compare with Python's operators, and know their precedence.
In this lesson10 parts
- 01Operators, operands and expressions
- 02The seven arithmetic operators, and the type each result has
- 03Floor division and modulo with negative numbers
- 04Precedence: which operator runs first, and the double star exception
- 05Comparison operators, chained comparisons, and assignment against comparison
- 06Logical operators: and, or, not, short circuit evaluation and returning an operand
- 07Augmented assignment: minus equals, plus equals, star equals and the rest
- 08Identity with is, and membership with in
- 09Why floats are not exact: isclose, storing cents, and rounding half to even
- 10Recap and your challenge
Key terms
The words this lesson introduces, each in one line. The module’s glossary collects them all.
- operator · operand · expression
+· the values it works on · code that evaluates to a value- precedence
- the order operators run in:
**, unary-,* / // %,+ -, comparisons,not,and,or
Quiz 5 questions
Answer each one in your head, or on paper, before you check it. Getting one wrong here is how the lesson sticks.
- 01
What is
10 / 5? - 02
What is
-7 // 2? - 03
What is
70 / 1.75 ** 2? - 04
What is
"" or "Guest"? - 05
What is
round(2.5)?
Practice
Problems to solve in your own notebook. Each states the problem, not the steps: working out the steps is the exercise. Level A applies the lesson, B combines it with earlier ones, C stretches it.
The self-checking notebook for this lesson is Notebook 3 · Input, Output and Operators.
Common mistakes
What you will see when it goes wrong, why it happens, and the fix.
Where it’s used
Where this lesson’s ideas turn up in real work.