📘 Python Variables Introduction
A Python Variable is a name used to store data inside memory. Variables allow Python programs to save numbers, text, lists, objects and many other values.
Python automatically decides the data type, so you don't need to declare it like C or Java.
💡 Quick Tip
Think of a variable as a labelled box. You give the box a name and store any value inside it.
⚠ Common Beginner Mistake
Don't use spaces in variable names. Example:
student name = "Roshni" ❌
student_name = "Roshni" ✅
📝 Python Variable Syntax
Python me variable banana bahut easy hai. Bas variable ka naam likho aur "=" ke baad value assign kar do.
x = 10
name = "Roshni"
price = 99.99
isStudent = True
💻 Python Variables Example
name = "Roshni"
age = 19
city = "Mumbai"
print(name)
print(age)
print(city)
✅ Output
Roshni
19
Mumbai
🖼 Python Variables Diagram
This diagram explains how a variable stores values inside Python memory.
📜 Python Variable Rules
- ✅ Variable name must start with a letter or underscore (_).
- ✅ It can contain letters, numbers and underscores.
- ❌ It cannot start with a number.
- ❌ Spaces are not allowed.
- ❌ Python keywords cannot be used as variable names.
- ✅ Variable names are case-sensitive.
✍ Python Naming Rules
| Valid ✅ | Invalid ❌ |
|---|---|
| student_name | student name |
| age2 | 2age |
| total_marks | total-marks |
| userName | class |
🔄 Assign Multiple Variables
You can assign values to multiple variables in one line.
x, y, z = 10, 20, 30
print(x)
print(y)
print(z)
✅ Output
10
20
30
🖨 Output Variables
Use print() to display variables.
name = "Roshni"
print(name)
age = 19
print(age)
💡 Tip
You can print multiple variables together.
print(name, age)
📝 Practice Questions
- What is a variable in Python?
- How do you create a variable?
- Can a variable start with a number?
- Why are variables used?
- Write a program to store your name.
- Create variables for age and city.
- Print two variables together.
- Assign multiple variables in one line.
- Differentiate valid and invalid variable names.
- What happens if two variables have the same value?
🧠 Mini Quiz (10 MCQs)
- Which symbol is used to assign a value?
A. = ✅ B. + C. * - Which is a valid variable?
A. age1 ✅ B. 1age C. age-name - Python variables are:
A. Case Sensitive ✅ - Which keyword prints output?
A. print() ✅ - Can variables store text?
A. Yes ✅ - Can Python change variable type automatically?
A. Yes ✅ - Which is invalid?
A. student_name B. student name ✅ - Which function shows output?
A. print() ✅ - Can multiple variables be assigned together?
A. Yes ✅ - Python variables store:
A. Data ✅
💼 Top 10 Interview Questions
- What is a Python variable?
- How is Python different from C in variable declaration?
- Explain dynamic typing.
- What are variable naming rules?
- What are identifiers?
- What is multiple assignment?
- What is unpacking?
- Difference between = and == ?
- Can variables change data type?
- Best practices for naming variables?
❓ Frequently Asked Questions
1. What is a variable?
A variable stores data.
2. Is Python case-sensitive?
Yes.
3. Can variable names contain spaces?
No.
4. Can variables store text?
Yes.
5. Can variables store numbers?
Yes.
6. Can Python change data type automatically?
Yes.
7. Which operator assigns values?
=
8. Can I assign multiple variables?
Yes.
9. What is print()?
It displays output.
10. Why are variables important?
They make programs dynamic and reusable.
📚 Summary
✔ Python variables store data.
✔ No datatype declaration is required.
✔ Python uses dynamic typing.
✔ Follow naming rules.
✔ Use meaningful variable names.