Python Data Types kya hote hain?
Jab hum Python me koi variable banate hain, toh us variable me store hone wali value ka ek type hota hai — isi ko Data Type kehte hain. Data type batata hai ki variable me kaisa data store ho sakta hai aur us par kaunse operations kiye ja sakte hain.
Python me mainly 8 built-in data types hote hain :-
- 1. int — Integer (pure numbers)
- 2. float — Decimal numbers
- 3. complex — Complex numbers
- 4. str — String (text)
- 5. list — Ordered, changeable collection
- 6. tuple — Ordered, unchangeable collection
- 7. set — Unordered, unique items
- 8. dict — Key-value pairs
- 9. bool — True / False
- 10. NoneType — No value (None)
Note :- Python me aapko manually data type declare nahi karna padta. Python khud automatically detect kar leta hai ki variable ka type kya hai — ise Dynamic Typing kehte hain.
1. Numeric Types — int, float, complex
In teeno types me numbers store hote hain, bas unka format alag hota hai.
| Type | Matlab | Example |
|---|---|---|
| int | Pura number (koi decimal nahi) | 10, -5, 0, 1000 |
| float | Decimal wala number | 3.14, -0.5, 2.0 |
| complex | Real + Imaginary part | 3+2j, 5j, -1+0j |
Example 1: int — Integer numbers
Example 2: float — Decimal numbers
Example 3: complex — Real + Imaginary numbers
2. str — String (Text)
String ek text data type hai. Isme letters, words, sentences — kuch bhi store kar sakte hain. String ko single quotes (' ') ya double quotes (" ") me likha jata hai.
Example 1: String banana aur print karna
Example 2: String operations — length, indexing, slicing
Example 3: String Concatenation aur f-String
3. list — List
List ek ordered collection hai jisme multiple values store kar sakte hain. List changeable (mutable) hoti hai — iska matlab values baad me add, remove ya change ki ja sakti hain. List square brackets [ ] me likhi jaati hai.
Example 1: List banana aur access karna
Example 2: List me changes karna — append, remove, update
4. tuple — Tuple
Tuple bhi ek ordered collection hai — bilkul list ki tarah — lekin ye unchangeable (immutable) hota hai. Iska matlab ek baar banane ke baad isme koi change nahi ho sakta. Tuple round brackets ( ) me likha jata hai.
Example 1: Tuple banana aur access karna
Example 2: Tuple immutable hai — change karne par error
5. set — Set
Set ek unordered collection hai jisme duplicate values nahi hoti. Iska matlab agar aap same value baar baar daalo, toh bhi woh sirf ek baar store hogi. Set curly brackets { } me likha jata hai.
Example 1: Set banana — duplicates automatically remove hote hain
Example 2: Set Operations — union, intersection, difference
6. dict — Dictionary
Dictionary ek key-value pair collection hai. Jaise ek real dictionary me word (key) hota hai aur uska meaning (value) hota hai, waise hi Python dict me bhi kaam hota hai. Dict curly brackets { } me likha jata hai aur colon ( : ) se key-value alag hote hain.
Example 1: Dictionary banana aur access karna
Example 2: Dictionary me add, update aur delete karna
7. bool — Boolean
Boolean sirf do values rakh sakta hai — True ya False. Ye mainly conditions aur comparisons me use hota hai. Python me True = 1 aur False = 0 hota hai numerically.
Example 1: Boolean values aur comparisons
Example 2: Boolean numerically — True = 1, False = 0
8. NoneType — None
None ka matlab hai "koi value nahi". Ye ek special literal hai jo represent karta hai ki variable empty hai ya koi value assign nahi ki gayi. Iska type NoneType hota hai. Ye Java ya C ke null ki tarah hai.
Example 1: None ka use
Example 2: Function jab kuch return na kare — None milta hai
Quick Summary — Sabhi Data Types ek nazar me
| Type | Keyword | Example | Mutable? |
|---|---|---|---|
| Integer | int | x = 10 | — |
| Float | float | x = 3.14 | — |
| Complex | complex | x = 2+3j | — |
| String | str | x = "hello" | ❌ No |
| List | list | x = [1,2,3] | ✅ Yes |
| Tuple | tuple | x = (1,2,3) | ❌ No |
| Set | set | x = {1,2,3} | ✅ Yes |
| Dictionary | dict | x = {"a":1} | ✅ Yes |
| Boolean | bool | x = True | — |
| None | NoneType | x = None | — |