Data Types क्या है ?
Data Types Python मे बहुत महात्वपूर्ण भूमिका निभाते है | Variables मे stored Value के Type को Data Types कहा जाता है | Data Types Python का आधार होते है | Python मे data का type बताने की जरूरत नही होती है | Python खुद से variable मे stored value के type को पता कर लेता है | Python में Data Types को 6 वर्गों में बांटा गया है | और हर data Type को समझना बहुत जरूरी होता है |
1. Numeric Data Types क्या है ?
Numeric Data Type Python का पहला basic और समझने मे सरल data type है | जिसका उपयोग variable मे
Numeric value store करने के लिए किया जाता है | 1, 2, 4, 6, -3,.4 etc. Numeric values होती है | Numeric Data Type तीन
तरह का होता है |
1. Float Float Numeric Data Type का एक प्रकार है | जो decimals
numbers को store करने के काम आता है | decimal numbers वो होते है | जो point(.) से शुरू होते है , जैसे :- .88, .33 etc.
नीचे एक variable मे float value store करने का code दिया गया है |
1x = .6 2print(type(x))
<class 'float'> ></class>
Syntax Explanations
x = 6 x नाम का एक variable create किया गया है | जिसमे .6 value को assignment
Operator की मदद से store किया गया है |
print(type(x)) का मतलब है कि display करो x variable मे store value के type को |
NOTE : type एक built in function है | जिसका उपयोग किसी value के type को पता करने के लिए किया जाता है |
2. Interger Integer Numeric Data Type का एक प्रकार है | जो Integer numbers को store करने के काम आता है | ये Integer numbers Positive या negative हो सकते है | 3, 5, -8, -2 etc. Integer numbers है | नीचे एक variable मे Integer value store करने का code दिया गया है |
1x = 5 2print(type(x))
<class 'int'> ></class>
3. Complex complex numbers को store करता है | complex numbers के 2 भाग होते है real और imaginary एक 5 + 4j एक complex number है | नीचे एक variable मे complex value store करने का code दिया गया है |
1x = 5 + 4j 2print(type(x))
<class 'complex'> ></class>
Syntax Explanations
x = 5 + 4j x नाम का एक variable create किया गया है | जिसमे एक complex value को assignment
Operator (=) की मदद से store किया गया है |
print(type(x)) का मतलब है कि display करो x variable मे store value के type को |
2. Boolean Data Type क्या होते है ?
Boolean एक ऐसा data type होता है | जिसमे True या False Value store की जाती है | Boolean Data Type का अधिक उपयोग conditions को check करने मे किया जाता है | जैसा Operator chapter मे किया गया था | उदाहरण के लिए ,
1a = 5 2b = 8 3print(a < b) 4yes = True
True
Syntax Explanations
a और b नाम के 2 variables create किए गए है | जिनमे integer values store की गई है | और एक yes नाम का variable create किया गया है , जिसमे True value store कि गई है | अब result True या False मे मिलेगा |
3. Set Data Type क्या होता है ?
Set एक data Structure और Data का Type दोनों होता है | वो ऐसे
se = {3, 5, 6}
अगर आप से पूछा जाए की se variable मे किस type का data stored है | तो जवाब होगा , की set type का |
यहाँ se variable मे एक set create किया गया है और उसका data type भी set है |
set को curly{} brackets मे create किया जाता है | एक set
को create करने का code नीचे दिया गया है |
1s = {2, 1, 5, 8} 2print(type(s))
<class 'set'>
Syntax Explanations
s variable मे set type का data store किया गया है | फिर print function से s variable मे store value के type को पता किया गया है |
4. String क्या होता है ?
String एक Immutable data Type है | यानि की create की गई string मे changes नही किए जा सकते है | text को store करने के लिए String data Type का उपयोग किया जाता है | String को Single quotes , Double quotes या triple quotes मे create किया जा सकता है | String के साथ मे indexing , slicing etc. जैसे operations perform किए जा सकते है | NOTE : यदि आप को किसी variable मे text को store करना है | तो text को store करने के लिए केवल एक ही data type है | जिस data Type का नाम String , एक string को create करने का code निम्नलिखित दिया गया है |
1st = "Hello" 2print(type(st))
<class 'str'>
Syntax Explanations
st = "Hello" st एक variable है | जिसमे text data को store करने के लिए String
data type का उपयोग किया गया है और String को Single quotes मे लिखा गया है | फिर
print(type(st)) st variable मे stored value के type को पता करने के लिए type function का
उपयोग किया गया है |
NOTE : Hello एक string है | string का perfectly उपयोग करने के लिए Python मे
कुछ string methods और functions का उपयोग किया जाता है | कुछ String methods और functions का निम्नलिखित वर्णन किया गया है |
1. string indexing (Method)
string indexing एक method है | जिसके उपयोग से string के किसी index number पर कया text है | को पता करने के लिए String indexing method का उपयोग किया जाता है | नीचे एक String indexing का example दिया गया है |
1st = "Hello" 2print(st[1])
e
Syntax Explanations
print(st[1]) का मतलब है कि display करो st variable मे stored value के index 1 number पर stored value को |
2. String Slicing (Method)
String slicing string का एक महात्वपूर्ण method है | जिसका उपयोग किसी एक starting index number से लेकर के किसी एक ending index number तक string मे store value को पता लगाने के लिए किया जाता है | जैसे :-
1st = "Hello" 2print(st[1 : 4])
ello
Syntax Explanations
print(st[1 : 4]) लिखा गया है कि display करो st variable मे store value के index number 1 से index number 4 तक stored value को | print() का उपयोग screen पर कुछ display करने के लिए किया जाता है |
3. String Concatenation (Method)
एक या एक से अधिक strings को आपस मे जोडने को String Concatenation (Method) कहा जाता है | बडे - बडे programs बनाते time string Concatenation method का उपयोग अधिक किया जाता है | नीचे string Concatenation का एक code लिखा गया है
1st = "Hello " 2name = "user" 2print(st + name)
Hello user
4. Len()
Python मे String methods के साथ - साथ कुछ string functions भी होते है | len एक built in function है | जिसके उपयोग से string की lenght पता की जा सकती है | जैसे :-
1st = "Hello " 2print(len(st))
5
इस code मे len function "Hello" string मे stored सभी characters की सांख्य को calculate करके बताता है | इस तरह से Python मे बहुत से string methods और string functions available है |
Dictionary Data Type क्या होता है ?
जैसा की आप पहले ही पढ़ चुके है कि Dictionary एक data Structure है | पर Dictionary किसी value का
Data Type भी हो सकती है जैसे :-
dict = {"name" : "user"}
अगर अब पूछा जाए की dict variable मे किस type का data stored है | तो जवाब होगा , की Dictionary type का
तो यहाँ dict variable मे एक Dictionary create की गई है और उसका data type भी Dictionary है |
5. Sequence Data Types
Sequence Data Types वो हो ते है जो डेटा को एक क्रम (sequence) में स्टोर करते हैं। Tuple , List , Range etc. Sequence Data Type है | अब तक आप ये समझ गए होगे की कोई data Structure Data का Type भी हो सकता है | Tuple , List और Range एक format मे data को store करने के काम आते है | जिस तरह से Dictionary एक data Structure और data का type होती है | उसी तरह से Tuple और List भी data Structure होने के साथ - साथ data का type भी होते है |
अध्याय समाप्त — आगे बढ़ें
आपने इस chapter मे python के बहुत ही महत्वपूर्ण concepts समझे है जो आगे की प्रोग्रामिंग सीखने मे बहुत Helpful हैं। आगे के chapter मे आप File Handling के बारे मे सिखेगे आगे के chapter की और बढ़ने के लिए नीचे दिए गए बटन पर क्लिक करे |
Next Chapter
Seekho Coding