🧠 What is a Variable?
A variable is a named space in memory used to store information. Think of it as a label on a jar — the label (variable name) helps you identify what's inside (the value).
name = "Alice"
age = 25
Here, name and age are variables that store a string ("Alice") and a number (25), respectively.
🔤 Types of Variables
Different programming languages support different data types. Common types include:
- Integer (int): Whole numbers (e.g., 1, 100, -5)
- Float: Decimal numbers (e.g., 3.14, -0.01)
- String (str): Text (e.g., "hello", "123")
- Boolean (bool): True or False values
is_student = True # Boolean
height = 5.9 # Float
🧾 Rules for Naming Variables
Good variable names make your code easier to read and understand. Here are some basic rules:
- ✅ Start with a letter or underscore (
_) - ✅ Use only letters, numbers, and underscores
- ❌ Don’t start with a number
- ❌ Avoid using reserved keywords (like
if,while,class)
# Valid names
user_name = "john"
score = 98
# Invalid names
# 1name = "wrong" ❌
# if = 5 ❌
🔄 Variables are Changeable
You can change the value of a variable at any time in your code:
score = 50
score = 75 # Now the value of score is 75
🧪 Why Variables Matter
Variables let your programs be dynamic and flexible. Instead of hardcoding values, you can use variables to:
- Accept input from users
- Store results from calculations
- Control program flow
name = input("Enter your name: ")
print("Hello, " + name + "!")
🌐 Final Thoughts
Variables are the foundation of any programming language. Mastering how they work is the first step to becoming a skilled coder. Start experimenting with them in small programs — you'll be surprised at how powerful they can be!





