CHAPTER 02
📦 Variables & Data Types
Variables, Data Types, aur Type Conversion Hindi mein
Advertisement
Variable kya hota hai?
Variable ek naam wala dibba hai jisme aap data store kar sakte hain. Python mein variable banana bahut aasan hai — bas naam likho, = lagao, aur value do. Koi type declare nahi karna padta!
python
# Variable banana name = "Rahul" # String age = 20 # Integer height = 5.8 # Float student = True # Boolean print(name, age, height, student) # Ek saath multiple variables x, y, z = 10, 20, 30 print(x, y, z) # 10 20 30
OUTPUT
Rahul 20 5.8 True10 20 30
Variable Naming Rules
Variable ka naam rakhte waqt ye rules follow karo:
| ✅ Sahi naam | name, age, my_name, firstName, _private, age2 |
|---|---|
| ❌ Galat naam | 2name, my-name, my name, class (reserved word) |
Advertisement
Data Types — 4 mukhya types
Python mein char mukhya data types hain:
| int | 10, -5, 100 — Purna sankhya |
|---|---|
| float | 3.14, -2.5 — Dashamlav |
| str | "Rahul" — Text/String |
| bool | True/False — Sahi ya galat |
type() Function
type() se pata karo ki variable ka type kya hai:
python
print(type(42)) # <class 'int'> print(type(3.14)) # <class 'float'> print(type("Python")) # <class 'str'> print(type(True)) # <class 'bool'> print(type(None)) # <class 'NoneType'>
OUTPUT
<class 'int'><class 'float'>
<class 'str'>
<class 'bool'>
<class 'NoneType'>
Type Conversion
Ek type se doosre type mein convert karna:
python
# int() — integer mein convert print(int("42")) # 42 print(int(3.9)) # 3 (decimal cut) # float() — float mein print(float("3.14")) # 3.14 print(float(5)) # 5.0 # str() — string mein print(str(100)) # "100" # bool() — boolean mein print(bool(0)) # False print(bool(1)) # True print(bool("")) # False (khaali string)
OUTPUT
423
3.14
5.0
100
False
True
False
Practical: Student Info
Ab ek real example banao variables ka use karke:
python
# Student ki info store karo name = "Priya Sharma" age = 18 marks = 92.5 passed = True print("=== Student Info ===") print(f"Naam: {name}") print(f"Umar: {age} saal") print(f"Ank: {marks}%") print(f"Pass: {passed}")
OUTPUT
=== Student Info ===Naam: Priya Sharma
Umar: 18 saal
Ank: 92.5%
Pass: True
Variables Deep Dive — Sab Kuch Samjho
Variable ek memory location ka naam hai. Jab aap
Python mein variables dynamically typed hain — matlab aapko type declare nahi karni padti. Python khud detect karta hai ki value ka type kya hai.
x = 10 likhte hain,
Python memory mein ek jagah 10 store karta hai aur us jagah ka naam x rakh deta hai.
Baad mein jab bhi x use karo — Python wahan se value nikal deta hai.Python mein variables dynamically typed hain — matlab aapko type declare nahi karni padti. Python khud detect karta hai ki value ka type kya hai.
python
# Python khud type detect karta hai x = 10 # int x = "Hello" # ab string! Same variable x = 3.14 # ab float! # Java/C++ mein yeh possible nahi — Python mein hai! # Multiple assignment a = b = c = 0 # teeno 0 hain x, y = 10, 20 # tuple unpacking a, b = b, a # swap! Temp variable nahi chahiye
Data Types — Poori List
| Type | Example | Use Case | Mutable? |
|---|---|---|---|
| int | 42, -10, 0 | Age, count, ID | No |
| float | 3.14, -2.5 | Price, height, % | No |
| str | "Hello", 'Python' | Name, message | No |
| bool | True, False | Conditions, flags | No |
| list | [1, 2, 3] | Collection of items | Yes ✅ |
| tuple | (1, 2, 3) | Fixed collection | No |
| dict | {"key": "val"} | Key-value data | Yes ✅ |
| set | {1, 2, 3} | Unique items | Yes ✅ |
| None | None | Empty/null value | No |
Constants — Unchangeable Values
Python mein official constants nahi hote lekin convention hai:
python
# UPPERCASE = constant (convention) PI = 3.14159 MAX_SIZE = 100 DB_NAME = "mydb.sqlite" BASE_URL = "https://api.example.com" # In flags DEBUG = True TESTING = False
Practical Project — Student Card
python — student_card.py
# Student ka complete profile name = input("Naam: ") roll = int(input("Roll Number: ")) age = int(input("Umar: ")) percentage = float(input("Percentage: ")) passed = percentage >= 33 print(" " + "="*35) print(" STUDENT REPORT CARD") print("="*35) print(f"Naam : {name}") print(f"Roll No : {roll}") print(f"Umar : {age} saal") print(f"Percentage : {percentage:.1f}%") print(f"Result : {'PASS ✅' if passed else 'FAIL ❌'}") print("="*35)
OUTPUT
===================================STUDENT REPORT CARD
===================================
Naam : Priya Sharma
Roll No : 101
Umar : 18 saal
Percentage : 92.5%
Result : PASS ✅
===================================
Interview Mein Pooche Jane Wale Sawal
Job interviews mein is topic se yeh sawal aksar pooche jaate hain:
| Sawal | Short Answer |
|---|---|
| Python mein memory kaise manage hoti hai? | Automatic garbage collection — reference counting se |
| Python interpreted hai ya compiled? | Interpreted — line by line execute hota hai |
| Python 2 aur 3 mein fark? | Python 2 dead hai — hamesha Python 3 use karo |
| GIL kya hai? | Global Interpreter Lock — ek time par ek thread run hota hai |
| Mutable aur Immutable mein fark? | Mutable = badal sakta hai (list, dict). Immutable = nahi badlta (int, str, tuple) |
Aur Seekho — Resources
Python aur deep seekhne ke liye yeh resources use karo:
Free Resources:
✅ docs.python.org — Official Python documentation
✅ pythonhindi.in — Hamare sab chapters aur projects (aap yahaan hain!)
✅ w3schools.com/python — Quick reference
✅ realpython.com — Advanced tutorials
✅ YouTube — Hindi mein Python tutorials
Practice Platforms:
✅ HackerRank — Python challenges
✅ LeetCode — Problem solving
✅ Codewars — Fun challenges
✅ Project Euler — Math + Programming
Books (Recommended):
✅ "Python Crash Course" — Eric Matthes
✅ "Automate the Boring Stuff" — Al Sweigart (Free online!)
✅ "Fluent Python" — Advanced ke liye
Free Resources:
✅ docs.python.org — Official Python documentation
✅ pythonhindi.in — Hamare sab chapters aur projects (aap yahaan hain!)
✅ w3schools.com/python — Quick reference
✅ realpython.com — Advanced tutorials
✅ YouTube — Hindi mein Python tutorials
Practice Platforms:
✅ HackerRank — Python challenges
✅ LeetCode — Problem solving
✅ Codewars — Fun challenges
✅ Project Euler — Math + Programming
Books (Recommended):
✅ "Python Crash Course" — Eric Matthes
✅ "Automate the Boring Stuff" — Al Sweigart (Free online!)
✅ "Fluent Python" — Advanced ke liye
Python Career Guide 2026
Python seekhne ke baad career ke kitne options hain — poori list dekho:
Job Roles aur Salary (India 2026):
Job Roles aur Salary (India 2026):
| Role | Skills | Salary Range |
|---|---|---|
| Junior Python Developer | Python basics, Flask/Django | Rs 3-6 LPA |
| Python Developer | 2-3 years exp, APIs, DB | Rs 6-12 LPA |
| Senior Python Developer | 5+ years, System design | Rs 15-25 LPA |
| Data Analyst | Pandas, SQL, Visualization | Rs 5-12 LPA |
| Data Scientist | ML, Statistics, Python | Rs 8-20 LPA |
| ML Engineer | TensorFlow, PyTorch, Cloud | Rs 12-30 LPA |
| DevOps Engineer | Python scripts, Docker, CI/CD | Rs 8-18 LPA |
| Freelancer | Any Python skill | Rs 20,000-2,00,000/month |
💰 Tip: Python Developer ki demand 2026 mein record high hai India mein.
Abhi seekhna shuru karo — 6 mahine mein job ready ho sakte hain!
Chapter 2 — Deep Practice aur Mastery
Python sikhne ka sabse accha tarika hai — practice, practice, aur practice!
Variables Data Types ko properly master karne ke liye yahan kuch aur detailed examples hain
jo aapki understanding ko aur gehri karenge.
Yeh examples real projects se liye gaye hain — inhe samjho aur apne code mein use karo. Ek baar yeh concepts clear ho gaye, to aap confidently koi bhi Python project bana sakte hain.
Yeh examples real projects se liye gaye hain — inhe samjho aur apne code mein use karo. Ek baar yeh concepts clear ho gaye, to aap confidently koi bhi Python project bana sakte hain.
python — chapter02_advanced.py
# Chapter 2: Variables Data Types — Advanced Examples # Yeh code copy karo aur run karo! # Example 1: Basic concept print("=== Chapter 2: Variables Data Types ===") # Example 2: List operations items = ["Python", "Hindi", "Code", "Practice"] for i, item in enumerate(items, 1): print(f"{i}. {item}") # Example 3: Dictionary usage chapter_info = { "number": 2, "title": "Variables Data Types", "level": "Beginner", "done": False } for key, value in chapter_info.items(): print(f" {key:10}: {value}") # Example 4: Function def practice_summary(chapter, completed=False): status = "Complete ✅" if completed else "In Progress ⏳" return f"Chapter {chapter}: {status}" print(practice_summary(2)) print(practice_summary(2, True))
OUTPUT
=== Chapter 2: Variables Data Types ===1. Python
2. Hindi
3. Code
4. Practice
number : 2
title : Variables Data Types
level : Beginner
done : False
Chapter 2: In Progress ⏳
Chapter 2: Complete ✅
Python Community aur Help Kaise Lein
Python seekhte waqt aapko problems aayengi — yeh normal hai! Har developer ko aati hain.
Yahan bataya gaya hai ki help kahan se lein:
1. Error message padho:
Python ka error message bahut helpful hota hai. Jab error aaye to poora message padho — woh exactly batata hai kya galat hua aur kahan.
2. Google karo:
Error message ko quotes mein Google karo: "TypeError: unsupported operand" Mostly Stack Overflow par answer milega.
3. Stack Overflow:
stackoverflow.com — duniya ke sabse helpful developer community. Aapka koi bhi sawal already wahan answer ho chuka hoga!
4. Python Official Docs:
docs.python.org — har function ki complete documentation. Advanced learners ke liye must-read.
5. PythonHindi.in:
Hamare sab 30 chapters aur 60 projects free mein available hain. Koi concept samajh nahi aaya to related chapter dobara padho!
6. YouTube:
Hindi mein bahut saare Python tutorials available hain. Visual seekhne waalon ke liye perfect!
1. Error message padho:
Python ka error message bahut helpful hota hai. Jab error aaye to poora message padho — woh exactly batata hai kya galat hua aur kahan.
2. Google karo:
Error message ko quotes mein Google karo: "TypeError: unsupported operand" Mostly Stack Overflow par answer milega.
3. Stack Overflow:
stackoverflow.com — duniya ke sabse helpful developer community. Aapka koi bhi sawal already wahan answer ho chuka hoga!
4. Python Official Docs:
docs.python.org — har function ki complete documentation. Advanced learners ke liye must-read.
5. PythonHindi.in:
Hamare sab 30 chapters aur 60 projects free mein available hain. Koi concept samajh nahi aaya to related chapter dobara padho!
6. YouTube:
Hindi mein bahut saare Python tutorials available hain. Visual seekhne waalon ke liye perfect!
Chapter 2 — Final Quiz aur Revision
Chapter complete karne se pehle yeh quick revision karo:
✅ Is chapter ke main concepts kya hain?
✅ Koi bhi code example bina dekhke likh sakte ho?
✅ Ek real problem mein yeh concept kaise use hoga?
✅ Agla chapter ke liye ready ho?
Agar upar ke sawalon ka jawab haan hai — congratulations! Aap is chapter ke concepts samajh gaye hain. Agla chapter start karo!
Agar nahi — koi baat nahi! Yeh chapter dobara padho, examples run karo, aur phir agla chapter start karo. Learning mein time lagta hai — patience rakho!
✅ Is chapter ke main concepts kya hain?
✅ Koi bhi code example bina dekhke likh sakte ho?
✅ Ek real problem mein yeh concept kaise use hoga?
✅ Agla chapter ke liye ready ho?
Agar upar ke sawalon ka jawab haan hai — congratulations! Aap is chapter ke concepts samajh gaye hain. Agla chapter start karo!
Agar nahi — koi baat nahi! Yeh chapter dobara padho, examples run karo, aur phir agla chapter start karo. Learning mein time lagta hai — patience rakho!
🎯 QUICK QUIZ — Chapter 02
type() function kya return karta hai?
Advertisement
📝 Chapter Summary
Variables Python mein data store karne ka tarika hai. Har variable ka ek naam hota hai aur usme koi bhi value rakh sakte hain. Python mein type declare nahi karna padta!
🧠 Is Chapter ke Important Concepts
| Concept | Kya karta hai |
|---|---|
int | Pura number: 10, -5, 100 |
float | Decimal number: 3.14, -2.5 |
str | Text: 'Rahul', 'Python' |
bool | True ya False |
type() | Variable ka type pata karo |
int(), float(), str() | Type convert karo |
💡 Pro Tips — Dhyan Rakho!
Yeh tips beginners aksar miss karte hain:
- Variable naam lowercase mein likho — Python convention
- Meaningful naam rakho: age, not a
- int() se sirf numbers convert hote hain, letters nahi
- bool mein 0 = False, baaki sab = True
- None = koi value nahi — NoneType
🏋️ Practice Karo — Khud Try Karo!
Chapter complete karne ke baad yeh exercises khud banao:
- Apni 5 personal details variables mein store karo
- type() function se har variable ka type print karo
- String ko int mein convert karo aur 10 jodo
- Ek variable ki value doosre variable mein copy karo
- Boolean variables se experiment karo
❓ Aksar Pooche Jane Wale Sawal
Q: Kya variable naam Hindi mein rakh sakte hain?
A: Technically haan, lekin English names better practice hai.
A: Technically haan, lekin English names better practice hai.
Q: float aur int mein kya fark hai?
A: int = 10, 20 (koi decimal nahi). float = 10.5, 3.14 (decimal ke saath).
A: int = 10, 20 (koi decimal nahi). float = 10.5, 3.14 (decimal ke saath).
Q: None kab use karte hain?
A: Jab variable abhi empty hai ya koi value nahi milni — jaise database se data na aaye.
A: Jab variable abhi empty hai ya koi value nahi milni — jaise database se data na aaye.
Q: Variable overwrite ho sakta hai?
A: Haan! x = 10, phir x = 20 karo — x ab 20 ho jaayega.
A: Haan! x = 10, phir x = 20 karo — x ab 20 ho jaayega.