Learn the concept
An expression produces a value. Assignment binds a name to that value. Python names do not declare a fixed type, but the values they refer to do have types. Integers represent whole numbers, floats approximate real numbers, strings hold text, and Booleans represent true or false.
Use names that describe meaning, such as ticket_count, rather than abbreviations that hide the domain. Reassignment changes which value a name refers to. It does not retroactively change a previously computed result.
Conversions are explicit when input arrives as text. int("12") produces an integer, while int("twelve") raises an exception. Do not assume that all text can be converted. Floating-point arithmetic is approximate; reserve integer minor units or decimal arithmetic for quantities requiring exact decimal behavior.
Run and inspect
count = 3
price = 2.5
total = count * price
count = 4
assert total == 7.5
assert isinstance(count, int)
assert int("12") == 12
Your exercise
Create variables for a document name, page count, and whether it is active. Calculate a derived value, then reassign an input and explain why the previous result stays unchanged.
Check your understanding
You distinguish a string containing digits from a number and can predict the value of each expression before running it.