Quick Stats
Completed
0
Time Spent
0m
Streak
0
User
Values, Variables, and Types
The building blocks.
Storing information
Every program is really just moving and transforming values — numbers, text, true/false flags. A variable is simply a name you attach to a value so you can refer to it later. In Python you don't declare types; you assign, and Python figures out the type for you:
name = "Ada" # str — text
age = 36 # int — whole number
ratio = 0.75 # float — decimal
is_active = True # bool — True or FalseRead = as "gets" — "name gets 'Ada'." You can reassign freely, and you can check a value's type any time with type(age).
The core types
Four basic types carry most of the load:
- str — text, in quotes. Join with
+, format with f-strings:f"Hi {name}". - int and float — numbers, whole and decimal, with the usual
+ - * /. - bool —
TrueorFalse, the basis of every decision.
Collections you'll use constantly
Single values only get you so far; real data comes in groups. Three collections appear everywhere in AI work:
- list — ordered and changeable:
[1, 2, 3]. Add with.append(), grab by position withnums[0]. - dict — key/value pairs:
{"name": "Ada", "age": 36}. Look things up by name:person["name"]. Perfect for structured records. - tuple — ordered but fixed:
(lat, lon). Use it for values that belong together and shouldn't change.
Get comfortable with lists and dicts above all — almost all data work is moving information in and out of them, and every dataset you load becomes some combination of the two.
Variables name values; collections group them. Masterlist(a row of things) anddict(labeled things) and you can represent almost any data you'll meet.
Try this: In a notebook, make a dict describing yourself — name, age, and a list of hobbies — then print one field and append a new hobby to the list. Storing and updating structured data like this is most of what code does.