P01.2 · Values, variables and types
P01.2 L0 · Foundation 4 lessons · about 100 min Live · in review
Part of P01 Python from Zero in the Programming and Data track.
What a program actually holds in memory, and what it does with it. These four lessons give every value a type and show why the type decides what an operator does, draw the course’s memory diagram of names pointing to objects, reduce arithmetic to one value by fixed rules, and end with the comparisons and the and, or and not that every condition in a program is built from, all on the scores of the course’s study table.
What you need first. How a program runs one line at a time, print, whole-number arithmetic, reading a trace table, and memory as a row of numbered cells (P01.1). School arithmetic is the only maths assumed.
Lessons
Values and their types P01.2.1 25 min
Every value in Python has a type, and the type decides what an operator does with it. Meet int, float, str, bool and None, convert between text and numbers with int, float and str, and see why 0.1 + 0.2 prints 0.30000000000000004.
Names and assignment P01.2.2 25 min
A name in Python is a label on an object, not a box that holds a value. Learn the two steps of every assignment, draw the course’s memory diagram line by line for x = 5, y = x, x = x + 1, and choose names that Python accepts.
Arithmetic and expressions P01.2.3 25 min
Python reduces every expression to one value by fixed rules. Learn its arithmetic operators and their order, draw an expression as a tree, see why / always gives a float, and tie // and % together with a = (a // b) * b + a % b, for negative numbers too.
Comparisons and boolean logic P01.2.4 25 min
Comparisons such as score >= 50 answer True or False. Chain them as in 0 <= score <= 100, combine them with and, or and not, see how and and or stop as soon as the answer is known, and learn why 0.1 + 0.2 == 0.3 is False and how to compare floats safely.
The interactive
P01.2-X1 · Memory-diagram builder. Run assignment statements such as x = 5, y = x and x = x + 1 one at a time. Names appear on the left, objects on the right, and the arrows redraw after every statement; a read-out says which names share an object, and an object left with no name fades away. It lives in Names and assignment.