Memory boxes: run code one line at a time
Each variable is a labelled box in memory. Step through the code and watch which box changes, what it now holds, and what type of value it is.
Memory
Output
What to notice
=means store: the value on the right goes into the box named on the left.x = x + 1reads the old value first, then stores the new one.- Nothing updates by itself:
sharekeeps its old value until a line recalculates it.
Try this
Operators: one pair of numbers, every operator
Change a and b and watch every result and its type update. Try negative numbers, decimals and zero.
Type whole numbers (like 7) or decimals (like 7.0).
Quick pairs
What to notice
/always gives a float, even for10 / 5.//rounds down, towards minus infinity:-7 // 2is-4, not-3.- One float anywhere makes the whole result a float.
Try this
Text tools: the first building blocks of a spam filter
Type any message. Every box shows exactly what Python returns for it, live.
Positions (indexes): top row counts from the start, bottom row from the end
Your own expression
Use the names message and word, for example message.lower().count("e").
What to notice
len()counts every character, spaces included."free" in messageis case-sensitive:FREEdoes not match until you use.lower().- Indexes start at 0, and
-1is always the last character.
Try this
f-strings: put values into sentences
Move the sliders. Each {…} in the f-string is calculated and replaced. After a colon you can choose the format.
Your f-string
Insert a format
Output
How each {…} was filled
What to notice
- Forgetting the
fprints the braces literally. :.0%multiplies by 100 and adds a percent sign;:.2fkeeps two decimals.- Rounding of exact halves goes to the even digit, as in
round().