🚀 What are Variables?
Variables are containers that store data in your program. Think of them as labeled boxes where you can put different types of information and use them later.
💡 Real-World Analogy
Imagine variables like storage containers in your kitchen:
- Each container has a label (variable name)
- You can put different things inside (data)
- You can change what’s inside anytime
- The label helps you find what you need quickly
🎯 Key Concepts
- Variable: A named storage location in memory
- Assignment: Putting a value into a variable using =
- Data Type: The kind of data a variable can hold
- Value: The actual data stored in the variable
📝 Common Data Types
- Integer (int): Whole numbers like 10, -5, 1000
- Float: Decimal numbers like 3.14, -0.5, 99.99
- String (str): Text like “Hello”, “Python”, “2024”
- Boolean (bool): True or False values
📝 Variable Examples
/code
Different variable types
name = “Alice” # String
age = 25 # Integer
height = 5.6 # Float
is_student = True # Boolean
print(“Name:”, name)
print(“Age:”, age)
print(“Height:”, height)
print(“Student:”, is_student)
Output:
Name: Alice
Age: 25
Height: 5.6
Student: True
⚡ Variable Naming Rules
- Must start with a letter or underscore
- Can contain letters, numbers, and underscores
- Cannot use special characters or spaces
- Case-sensitive (age and Age are different)
- Should be descriptive and meaningful
💭 Remember
- Variables make your code flexible and reusable
- Choose meaningful variable names
- You can change variable values anytime
- Different data types serve different purposes
🔥 Practice Challenge
Create variables for:
- Your favorite color (string)
- Your lucky number (integer)
- Your height in meters (float)
- Whether you like programming (boolean)
