Storing Information Like a Pro
"Variables are like labeled boxes for your data. Once you master them, you can build programs that remember information, make decisions, and interact with users!"
Variables = Labeled Storage Containers
# Like labeled boxes in your kitchen:
sugar_box = "White Sugar"
flour_box = "All-Purpose Flour"
spice_jar = "Cinnamon"name = "Alice"
age = 25
is_student = True# Strings are for text - use quotes!
name = "Sarah"
message = 'Hello, World!'
address = "123 Main Street"
# You can combine strings:
greeting = "Hello, " + name + "!"
print(greeting)Integers (Whole Numbers)
age = 25
students_count = 30
temperature = -5Floats (Decimal Numbers)
price = 19.99
pi = 3.14159
average = 85.6# Booleans are for yes/no, on/off, true/false
is_raining = True
has_license = False
is_logged_in = Trueuser_name = "Alice"Clear and descriptive
student_count = 30Easy to understand
is_logged_in = TrueReads like English
total_price = 99.99Specific purpose
a = "Alice"Too vague
x = 30What does x mean?
temp = TrueUnclear purpose
n = 99.99Meaningless
Create a user profile with different types of variables:
# CREATE a user profile with variables:
name = "Alice"
age = 25
city = "New York"
is_student = True
favorite_number = 7
# Test your profile:
print("=== USER PROFILE ===")
print("Name:", name)
print("Age:", age)
print("City:", city)
print("Student:", is_student)
print("Favorite Number:", favorite_number)Create a simple shopping cart calculator:
# CREATE a simple shopping cart:
item1 = "Python Book"
price1 = 29.99
item2 = "Laptop Mouse"
price2 = 15.50
total = price1 + price2
print("=== SHOPPING CART ===")
print("Item 1:", item1, "- $", price1)
print("Item 2:", item2, "- $", price2)
print("TOTAL: $", total)❌ Wrong
name = Alice✅ Correct
name = "Alice"❌ Wrong
age = "25"✅ Correct
age = 25❌ Wrong
is_valid = true✅ Correct
is_valid = True✓ Correct answer: C) first_name - Uses underscore instead of spaces and doesn't start with a number
✓ Correct answer: C) Boolean - True and False are boolean values
"Variables that store text are called strings, while whole numbers are called integers."
In Step 5, you'll learn about Basic Operations - how to do math, combine text, and make comparisons in Python!
"Naming variables well is one of the most important programming skills. Good names make your code readable and maintainable. Think: 'If someone else read this code, would they understand what each variable stores?'"
# CREATE a personal diary entry using variables:
mood_today = "Happy"
hours_slept = 8
books_read = 2
learned_something_new = True
today_quote = "Stay curious and keep learning!"
print("=== MY DIARY ===")
print("Mood:", mood_today)
print("Hours Slept:", hours_slept)
print("Books Read This Week:", books_read)
print("Learned Something New:", learned_something_new)
print("Today's Quote:", today_quote)You now know how to store data in variables! Next, you'll learn how to manipulate that data with math, text operations, and comparisons.