Variables & Data Types
Welcome to Python Foundations. Every program starts the same way — giving names to pieces of information so you can use them later. That's a variable, and it's the first building block for everything else this semester, including the text adventure game you'll start putting together over the next few classes.
What You'll Learn
- str (string) — text, always in quotes —
character_name = "Zara" - int (integer) — a whole number, no quotes —
health = 100 - float (decimal) — a number with a decimal point —
damage_multiplier = 1.5 - bool (boolean) — exactly
TrueorFalse, no quotes —is_alive = True
Python figures out the type automatically from the value you give it — you never have to declare it yourself. The built-in type() function tells you what type any variable actually is.
True/False are capitalized with no quotes — true, false, and "True" are all something else entirely.
Today's Activity
Today's practice happens inside the notebook below — work through it top to bottom:
- A worked example, fully written out
- Two guided practices — change a few values, then fill in some blanks
- Two independent practices — write your own from scratch, different scenario each time
- An optional stretch, if you want to go further
- One check-your-understanding question to close
Download the notebook, save it into your 1_foundations folder in your cloned repo, and open it in VS Code. Commit once you've saved it, then commit again when you're done for the day.
New to notebooks? See Using Jupyter Notebooks first.
What's Next
Coming up: 1.2 — Input/Output & f-strings, where your programs start talking back.