2 Ā· Variables & primitive types
Names that hold values, and the four primitive types every Python program uses.
A variable is a label pointing at a value ā assign with `=`, never `==`.
Without this:
Without variables, you cannot reuse a value, name an intermediate result, or build anything beyond a one-shot script.
Python is dynamically typed: a variable's type is the type of whatever value it currently holds. Bind a value to a name with =.
Python (in browser)
Four variables, four different primitive types. Run it and check the type() output.
Python runs entirely in your browser via Pyodide (~6 MB on first Run, cached after).
f-strings are the modern way to interpolate values into text. They start with f and embed expressions in {}.
Python (in browser)
Python runs entirely in your browser via Pyodide (~6 MB on first Run, cached after).
Shebang line + module docstring + a top-level CONSTANT in UPPER_SNAKE_CASE. The conventions you'll see in real codebases.
If 'function' and 'value' feel hand-wavy, read the MML opener ā it grounds the mental model.
- Variables are bindings (name ā value), not boxes. Reassignment changes what the name points at.
- The four primitives ā `int`, `float`, `str`, `bool` ā cover most simple values you'll see.
Hyperparameters are variables (`learning_rate = 0.01`); model state is held in variables (`model = LinearRegression()`).
If you remove it: Without named state, every experiment becomes a wall of literal numbers ā unreadable and untunable.