Learning Objectives: After this lesson, you'll understand how Python stores data with variables, explore fundamental data types, and see how Python manages memory automatically.
Understanding Variables
Think of variables as labeled containers that store data. Unlike some programming languages, Python variables are more like name tags attached to data rather than fixed storage boxes.
Loading Python runtime...
Variable Naming Rules
Python has specific rules for naming variables:
✅ Valid | ❌ Invalid | Why? |
---|---|---|
user_name | user-name | No hyphens allowed |
age2 | 2age | Can't start with number |
_private | class | class is a reserved word |
firstName | first name | No spaces allowed |
Loading Python runtime...
Python's Built-in Data Types
Python has several fundamental data types. Let's explore each one:
1. Numbers (int and float)
Loading Python runtime...
2. Strings (Text Data)
Loading Python runtime...
3. Booleans (True/False)
Loading Python runtime...
Memory Visualization
Let's see how Python manages memory for different variables:
Loading Python runtime...
Type Conversion
Python can convert between different data types:
Loading Python runtime...
Variable Tracker in Action
Let's see multiple variables working together:
Dynamic Typing
Python is dynamically typed, meaning variables can change their type:
Loading Python runtime...
Practical Examples
Example 1: User Profile
Loading Python runtime...
Example 2: Temperature Converter
Loading Python runtime...
Common Mistakes to Avoid
Loading Python runtime...
Practice Exercises
Exercise 1: Personal Information
Loading Python runtime...
Exercise 2: Shopping Calculator
Loading Python runtime...
Key Takeaways
✅ Variables are labels - They point to data in memory, not storage boxes
✅ Dynamic typing - Variables can change type during program execution
✅ Four basic types - int, float, str, bool cover most basic needs
✅ Type conversion - Use int(), float(), str(), bool() to convert between types
✅ Good naming - Use descriptive, consistent variable names
✅ Memory management - Python handles memory automatically
Next Steps
In the next lesson, we'll learn about making decisions with conditions - how to use if statements, comparison operators, and boolean logic to control program flow.
Ready to make your programs smarter? The next lesson will teach you how to make decisions in code!