Data Types क्या होते हैं?
Data type के बारे में जानने से पहले हमें ये पता होना चाहिए कि हमारा Data अलग-अलग प्रकार का हो सकता है जैसे आप अपना नाम लिखने के लिये letters का use करते हैं जबकि अपनी age लिखने के लिये आप numbers का use करते हैं इसी तरह से आप समझ सकते हैं कि आपका Name और Age दोनों अलग-अलग तरह के Data Type हैं इसी तरह Python में variables के अन्दर अलग-अलग types की values store की जाती है जैसे कि किसी variable के अन्दर numeric value तो किसी दूसरे variable के अन्दर alphabetic value store की जाती है, और जो हमें उस variable की value का type बताता है कि variable के अन्दर किस type की value store है उसी को हम data type कहते हैं और हर एक variable का कोई ना कोई Data type होता है, Data type के basis पर ही system ये recognize करता है कि उसके लिए कितनी memory allocate करनी है और उसको किस तरह से memory में handle करना है। Python में जितने भी Data types हैं वो classes हैं और variable जो हैं वो उनके objects हैं।
Python में Data Types छः प्रकार के होते है |
- Number
- String
- List
- Tuple
- Dictionary
- Set
1. Number Data Types in Python
Number Data Types के तीन प्रकार होते है |
- Integer Number Data Type
- Floating-point Number Data Type
- Complex Number Data Type
Note : type() function का इस्तेमाल data type check करने के लिए किया जाता है |
1.1 Integer Number Data Type
Integer data type ये normal numeric values होती हैं। इनमें कोई भी pointed value नहीं होगी।
Example: x = 7 y = 5885 z = 51865567 print(x) print(y) print(z) print(type(x)) print(type(y)) print(type(z)) Output : 7 5885 51865567 <class 'int'> <class 'int'> <class 'int'>
1.2 Floating-point Number Data Type
जब किसी number में fractional part आ जाता है तो वहाँ पर Floating-point number data type का use किया जाता है।
Example: a = 2.0 b = 12545885.568444444444445 c = 422154986446513513878678541351865465.4547878541516546845 print(x) print(y) print(z) print(type(x)) print(type(y)) print(type(z)) Output: 2.0 12545885.568444444 4.121549864465135e+35 <class 'float'> <class 'float'> <class 'float'>oat'>
1.3 Complex Number Data Type
Complex number, integer और float number से काफी अलग होते हैं। Complex data type ‘x + yi’ इस form में होता है इसमे ‘x’ ये real part होता है और ‘y’ ये imaginary part होता है |
Expample: x = 1 + 4i y = 5 + 4758499i print(x) print(y) print(type(x)) print(type(y)) Output: (1+4i) (5+4758499i) <class 'complex'> <class 'complex'> Complex number का Program देखने के लिये यहाँ clik करें।
2. String Data Type in Python
String ये characters का set होता है। जैसे किसी का नाम ‘Navin’ या कोई word जैसे “how” या कोई एक line “what is your name” हो सकते है। Python में string data types single(‘ ‘) या double(” “) quotes के अन्दर लिखे जाते है | String ये immutable data type है। immutable का मतलब यह है कि हम variable को एक बार value देने के बाद user उन values को update नहीं कर सकता है
Example: str1 = "Hello World" str2 = "Hello how are you" print(str1) print(str2) Output: Hello World Hello how are you
ज्यादातर Programming languages में string को index में print किया जाता है उसी प्रकार से Python में भी string को indexes से print किया जाता है | string के सबसे पहले character को index ‘0’ से शुरू होती है और string के सबसे आखिरी index ‘-1’ होती है |

Example: str = "Hello World" print("First letter in string :", str[0]) print("Last letter in string :", str[-1]) print("Second last letter in string :", str[-2]) Output: First letter in string : H Last letter in string : d Second last letter in string : l
String के बारे में अधिक जानने के लिए यहाँ click करे ।
3. List Data Type in Python
List, items का एक ordered sequence होता है Python के list data type में एक से ज्यादा items होते है | हर एक item को comma(,) से seperate किया जाता है | list के सभी items को square bracket[] के अन्दर close किये जाता है |
List ये एक compound data type है जिसमे किसी भी data types के items लिए जा सकते है | list ये एक mutable data type है | mutable data type का मतलब यह है कि user इन data type के items की values को update भी कर सकता है।
Example: list = [1, "Hello", 3.5, (1, "Hii")] for i in list: print(i) Output: 1 Hello 3.5 (1, 'Hii')
List Data Type के बारे में अधिक जानने के लिए यहाँ click करे |
4. Tuple Data Type in Python
Tuple भी list की तरह एक order of sequence item है Tuple और list में difference यह है कि tuple immutable होते हैं immutable का मतलब यह है कि हम data type के items को एक बार value देने के बाद user उन values को update नहीं कर सकता है Tuple के सभी items को parenthesis(()) के अन्दर close किये जाता है।
Example:
tuple = (1, "Hello", 5.6, (1, "Hii"))
for i in tuple:
print(i)
tuple[0] = 3 #trying to changing 0th index
print(tuple[0])
Output:
1
Hello
5.6
(1,'Hii')
Tuple Data Type के बारे में अधिक जानने के लिए यहाँ click करे |
5. Dictionary Data Type in Python
Dictionary Data Type में keys और values की pairs होती है | हर key value के pair को comma(,) से और key और value को colon(:) से seperate किया जाता है | Dictionary के सभी keys और values को curly braces({}) में लिखा जाता है | ये एक immutable data type है |
Example: dict = {1:"H", 5:"e", 7:"l", 8:"l", 9:"o"} print(dict[5]) print(dict[9]) Output: e o
Dictionary Data Type के बारे में अधिक जानने के लिए यहाँ click करे।
6. Set Data Type in Python
Set Data Type ये items का unordered collection होता है | set में दिए हुआ हर एक item नया होता है | अगर duplicate item मिल जाता है तो उसे remove किया जाता है | set data type के items को curly braces({}}) के अन्दर लिखा जाता है |
Example: set1 = {"Navin", "Amit", "Aman"} for i in set1: print(i) set2 = {3, 5, 8, 7, 1, 3} for j in set2: print(j) Output: Navin Amit Aman
Python Programs के लिये यहाँ click करें।