Values, variables and expressions
How does a program remember information?
Understand it
A value is a piece of data such as a number, text or true/false choice. A variable gives a value a useful name. Expressions combine values with operators, and Python evaluates the expression before storing or displaying the result.
Choose a step to inspect it, or run the complete sequence.
A useful analogy
A labelled container tells you what belongs inside and lets you replace its contents later.
Worked example
Store distance_cm = 42, safe_distance_cm = 25, then compare the two values to decide whether the path is clear.
length_cm = 12
width_cm = 8
area_cm2 = length_cm * width_cm
print(area_cm2) - Create variables for length and width.
- Calculate rectangle area.
- Change one input and predict the new result before running.
Quick checkWhat is the difference between = and == in Python?
Answer: = assigns a value to a variable. == compares two values and produces True or False.