Variables
Learn how to store and use data in your programs using variables.
What you'll learn:
- What a variable is and why we use them
- How to create and assign values to variables
- Different data types: strings, integers, and floats
- How to use variables in output with print()
Learning Path
Follow these activities in order.
1. Predict: What's in the box?
Predict what values variables will hold after code runs.
Foundation
Not Started
2. Study: Worked Example
See how to create and use variables step by step.
Core
Not Started
3. Investigate: Trace Variables
Track how variable values change through a program.
Core
Not Started
4. Modify: Arrange the Code
Put code blocks in order to create programs with variables.
Core
Not Started
5. Test: Knowledge Quiz
Check your understanding of variables.
Core
Not Started
Key Vocabulary
variable
A named container that stores a value. Like a labelled box that holds data.
assignment
Giving a value to a variable using the = sign. name = "Alice"
string
Text data, written in quotes. "Hello" or 'Hello'
integer
A whole number (no decimal point). 42, -7, 0
float
A decimal number. 3.14, -0.5, 100.0
data type
The kind of data a variable holds: string, integer, float, etc.
Quick Reference
variables_examples.py
# Creating variables
name = "Alice" # string
age = 15 # integer
height = 1.65 # float
# Using variables in print
print(name) # Prints: Alice
print("Hello", name) # Prints: Hello Alice
# Changing a variable's value
score = 10
score = score + 5 # Now score is 15
# Variable names: use lowercase, underscores for spaces
player_name = "Bob" # Good!
highScore = 100 # Works, but prefer snake_case