Operators & Expressions
Variables are only useful once you can do something with them. Today's about the operators that combine and compare values — the arithmetic you'd expect, plus a couple of Python-specific ones worth knowing early.
What You'll Learn
- Arithmetic:
+-*/(always gives a float),//(floor division),%(modulo — the remainder),**(exponent) - Comparison:
==!=<><=>=— each gives back abool, which is exactly what feeds into next lesson's conditionals - Order of operations: same rules as math class — exponents, then
*//////%, then+/-— use parentheses to force a different order
// and % are easy to mix up — // gives the whole number of times one value divides another, % gives just what's left over. Try saying out loud what real quantity each one represents if you're not sure which to use.
Today's Activity
Today's practice happens inside the notebook below — work through it top to bottom:
- A worked example, fully written out
- Two guided practices — change a few values, then fill in some blanks
- Two independent practices — write your own from scratch, different scenario each time
- An optional stretch, if you want to go further
- One check-your-understanding question to close
Download the notebook, save it into your 1_foundations folder in your cloned repo, and open it in VS Code. Commit once you've saved it, then commit again when you're done for the day.
New to notebooks? See Using Jupyter Notebooks first.
What's Next
Coming up: 1.4 — Conditionals, where your programs finally start making decisions.