Lesson 3 of 12

Variables & Data Types 💾

🎯 Grades 6–8 ⏱ ~25 minutes 💚 Intermediate

What You'll Learn

  • Create and use variables in Python
  • Understand the three main data types: int, float, and str
  • Use type() to check a variable's type

What Is a Variable?

A variable is a named container that stores a value. You create one by choosing a name, typing =, and then the value.

Python
name = "Alex"
age = 13
height = 5.2
print(name)
print(age)
💡
Naming Rules

Variable names: start with a letter or underscore, no spaces (use_underscores_instead), case-sensitive (score and Score are different variables).

The Three Main Data Types

  • 🔠 str (string) — text, always in quotes: "Hello" or 'Hello'
  • 🔢 int (integer) — whole numbers: 42, -7, 0
  • 🔣 float — decimal numbers: 3.14, 99.9
Python
city = "Tulsa"       # str
population = 413066  # int
temp = 98.6          # float
print(type(city))    # <class str>
print(type(population))

Updating Variables

Variables can change! Just assign a new value with =:

Python
score = 0
print(score)  # 0
score = 10
print(score)  # 10
score = score + 5
print(score)  # 15
👔Your Profile!

Create variables for: your name (str), your age (int), your grade (int), your GPA or a test score (float). Then print a sentence using each one.

Quick Check

Which data type stores text?

Aint
Bfloat
Cstr

What symbol do you use to create a variable?

A==
B=
C!=

What does type(42) return?

A
B
C