Why Variables Are Essential
Variables are named containers that store data values in memory. Think of them as labeled boxes where you can store information your program needs.
| Real World Analogy | Python Variable |
|---|---|
| Label on a storage box | name = "Azeem" |
| Number on a price tag | age = 25 |
| Shopping list items | fruits = ["apple", "banana"] |
The 6 Core Data Types
| Type | Example | Use Case | Mutable? |
|---|---|---|---|
| str | "Hello World" |
Text, names, messages | No |
| int | 42 |
Counts, IDs, ages | No |
| float | 3.14 |
Prices, measurements | No |
| bool | True |
Conditions, flags | No |
| list | [1, 2, 3] |
Ordered collections | Yes |
| dict | {"name": "Bob"} |
Key-value storage | Yes |
Strings - Text Mastery
Basic String Operations
f-Strings (Python 3.6+)
Lists & Dictionaries
Lists - Ordered Collections
Dictionaries - Key-Value Power
Tuples - Immutable Lists
Tuples are like lists but cannot be modified. Perfect for fixed data like coordinates or configuration values.
Practice Exercises
Exercise 1: Personal Profile
Create variables for your name, age, favorite color, and skills list. Print a formatted introduction using f-strings.
Exercise 2: Shopping Cart
Build a shopping cart dictionary with items and prices. Calculate total cost and add tax.
Exercise 3: Student Gradebook
Create a gradebook dictionary with multiple students. Calculate class average and find top performer.
Common Mistakes
Type Conversion
You've Mastered Variables!
✅ What You Can Now Build:
Store & display user data
Items, prices, totals
Multiple students & averages
Settings & preferences
Next Steps: Control Flow (if/else, loops) → Functions → Real Projects