Variables, types, and operators
Names, numbers, booleans, and None — the values every hyperparameter, metric, and flag is built from.
Why this matters in AI / ML / GenAI
Learning rates, batch sizes, temperature, max tokens, and confidence thresholds are ordinary Python values. Getting types wrong (string "0.2" instead of float 0.2) is a real production bug in config files and LLM API calls.
Names are labels, not boxes
A variable is a name bound to a value. Python does not make you declare a type. The value has a type; the name can be rebound later.
type(x) tells you the type. Use it while learning. In production you will prefer type hints (a later lesson) plus tests.
Common built-in types:
- int — whole numbers:
32,0,-1 - float — decimals:
0.001,3.14 - bool —
TrueorFalse(capital T/F) - str — text (next lesson)
- None — “no value”, used for missing optional settings
None is not the string "None" and not 0. Model APIs often use None to mean “use the server default”.
Operators you will actually use
Arithmetic: + - * / (always float) // (integer divide) % (remainder) ** (power).
Comparisons return bools: == != < > <= >=.
Logic: and, or, not. These show up in filters (“keep rows where score > 0.7 and label is not None”).
Division with / on two ints still returns a float (5 / 2 is 2.5). Use // when you need an int index into a list.
Copy-paste examples
Copy into your own editor, or load one into the compiler below and press Run.
Inspect types
type() is a learning tool. Read the output carefully.
epochs = 10
learning_rate = 3e-5
enabled = True
api_key = None
print(type(epochs), epochs)
print(type(learning_rate), learning_rate)
print(type(enabled), enabled)
print(type(api_key), api_key)Thresholds and flags
This is the same logic you will write for confidence filtering.
score = 0.82
threshold = 0.7
is_confident = score >= threshold
print("confident:", is_confident)
temperature = 0.2
use_greedy = temperature == 0
print("greedy decoding:", use_greedy)Integer vs float division
Batching often needs // to get a whole number of steps.
n_samples = 1000
batch_size = 32
n_batches = n_samples // batch_size
leftover = n_samples % batch_size
print("full batches:", n_batches)
print("leftover samples:", leftover)
print("true divide:", n_samples / batch_size)Practice: learning-rate sanity check
Try it — in-browser Python
Change learning_rate to 3e-2 and see whether the warning prints.
Output
Python runs in your browser. First run downloads the runtime.
Press Run (or Ctrl+Enter) to execute.
CPython in WebAssembly. Stdlib works. NumPy and pandas load on demand. No input(), no GPU, no network installs.
Takeaways
- Values have types (int, float, bool, None). Names just point at values.
- Use / for real division and // when you need a whole number.
- True/False/None are capitalized. They are not strings.