📚 What You'll Learn Today
Today you'll master the art of storing data in variables:
What variables are and why they're essential
Different data types: strings, numbers, booleans
How to name variables properly
Using variables in your programs
📦 What is a Variable?
Think of a variable as a labeled box where you store information. You can put something in, take it out, or change what's inside.
Creating a Variable:
name = "Alex"
age = 25
city = "New York"
💡 Analogy: The box is named "name" and it contains "Alex". The box is named "age" and it contains 25.
Using Variables:
print ("Hello, my name is " + name )
print ("I am " + age + years old" )
Hello, my name is Alex
I am 25 years old
🔢 Data Types
Python has several built-in data types. Here are the most common:
Data Type
Name
Example
Description
String
str
"Hello"
Text data
Integer
int
42
Whole numbers
Float
float
3.14
Decimal numbers
Boolean
bool
True / False
True or False
Examples:
greeting = "Hello, World!"
email = "alex@example.com"
year = 2026
score = 100
price = 19.99
pi = 3.14159
is_student = True
has_completed = False
📝 Naming Rules
Variable names in Python must follow these rules:
✅ Can use: letters, numbers, underscores
❌ Cannot start with a number
❌ Cannot use Python keywords (like print, if)
Case sensitive: Name ≠ name
Good Names:
user_name = "Alex"
email_address = "alex@example.com"
age_in_years = 25
total_score = 1500
Bad Names (will cause errors):
2nd_place = 2
class = 5
my-variable = "text"
🔄 Changing Values
You can change a variable's value at any time:
score = 10
print (score )
score = 20
print (score )
score = score + 5
print (score )
💡 Shortcut: You can use += to add: score += 5 means score = score + 5
🏋️ Exercise: Create Your Profile
Create variables for a user profile and print them out:
Bonus Challenge:
Calculate and print what your age will be in 10 years!
name = "Alex"
age = 25
likes_python = True
print ("Name:" , name )
print ("Age:" , age )
print ("Likes Python:" , likes_python )
print ("Age in 10 years:" , age + 10 )
🎭 Interactive Demo: Story Generator
Ready to see variables in action? Let's build a personalized story generator that uses all the variable types we just learned!
🚀 What You'll Build:
Collect user input (strings, numbers)
Store data in different variable types
Calculate new values using variables
Generate a personalized story with f-strings
Create magic spells based on user choices
💡 What This Demo Teaches:
How to use input() to get user data (strings)
Converting strings to numbers with int() and float()
Boolean logic for yes/no questions
Math operations with variables
Using f-strings to combine variables in text
✅ Key Takeaways
Variables store data with a label (name)
String = text ("hello")
Integer = whole numbers (42)
Float = decimals (3.14)
Boolean = True or False
Variable names: letters, numbers, underscores (can't start with number)
f-strings let you combine variables: f"Hello {name}"
You can do math with number variables: age + 10
🎉 Ready for Day 3?
Tomorrow you'll learn about conditions and loops - making decisions in your code!
✓ Mark Day 2 Complete
Marking complete will unlock Day 3!