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 True or False, 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.

Watch out for: a string without quotes isn't text — Python will think it's another variable and crash. And 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:

  1. A worked example, fully written out
  2. Two guided practices — change a few values, then fill in some blanks
  3. Two independent practices — write your own from scratch, different scenario each time
  4. An optional stretch, if you want to go further
  5. 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.

Download 1.1_Variables_and_Data_Types.ipynb

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.