This Website for Those Students who are searching for a platform to study online in their own Language Hindi, on this website they will learn all courses like IAS, programming, web designing, data science, and competitive exam preparation, etc.


Introduction to Data Types in Python

Introduction to Data Types in Python


Objective Of Today:

  1. numbers
  2. String
  3. list
  4. Tuple
  5. Dictionary
  6. Set

Data Types in Python

जब भी आप कोई variable create करते है तो उससे पहले compiler को बताते है की आप किस तरह का data उस variable में store करेंगे। इससे compiler उतनी ही memory उस variable को computer की memory में से allot कर देता है।
यदि किसी programming language में data types ना हो तो बहुत अधिक memory waste हो सकती है। जब 2 bytes की आवश्यकता हो तब 20 bytes आप waste कर सकते है। इसलिए जितनी भी तरह का data आप store कर सकते है उसके लिए पहले से ही maximum memory limit define की गई है।
Python में variables के अन्दर अलग-अलग types की values store की जाती है जैसे कि किस variable के अन्दर numeric value तो किसी दूसरे variable के अन्दर alphabetic value store की जाती है, इसे ही 'Data Types' कहा जाता है |

Python में 6 प्रकार के Data Types होते है |





  1. numbers
  2. String
  3. list
  4. Tuple
  5. Dictionary
  6. Set


1. Number Data Types in Python


Number Data Types के तीन प्रकार होते है |


Integer Number Data Type

Floating-point Number Data Type

Complex Number Data Type



Integer Number Data Type


Integer types किसी भी whole number (बिना दशमलव के) को store करने के लिए use किये जाते है।
Integer data type ये normal numeric values होती है | integer numbers को अपूर्णांकित हिस्सा नहीं होता है |

Source Code :




a = 5
b = 12545885
c = 412154986446513513878678541351865465

print(a)
print(b)
print(c)
print(type(a))
print(type(b))
print(type(c))

 


Note : type() function का इस्तेमाल data type check करने के लिए किया जाता है |

Output :






5
12545885
412154986446513513878678541351865465
  
<class 'int'>
<class 'int'>
<class 'int'>


 


Floating-point Number Data Type


Floating point data types को दशमलव संख्याओं को store करने के लिए define किया गया है।
Floating-point numbers को अपूर्णांकित हिस्सा होता है | Python में floating-point number के लिए कोई मर्यादा नहीं होती है |



7, 0, -2, 9, -55


 

Source Code :






a = 5.0
b = 12545885.568444444444445
c = 412154986446513513878678541351865465.4547878541516546845

print(a)
print(b)
print(c)
print(type(a))
print(type(b))
print(type(c))


 

Output :





5.0
12545885.568444444
4.121549864465135e+35
<class 'float'>
<class 'float'>
<class 'float'>


 


Complex Number Data Type


Complex data type 'a + bj' इस form में होता है इसमे 'a' ये real part होता है और 'b' ये imaginary part होता है |

Source Code :





a = 1 + 4j
b = 5 + 4758499j

print(a)
print(b)
print(type(a))
print(type(b))


 

Output :







(1+4j)
(5+4758499j)
<class 'complex'>
<class 'complex'>



 


String Data Type in Python



String ये characters का set होता है | characters; letters, numbers या special symbols हो सकते है | Python में single(' ') या double(" ") quotes के अन्दर लिखे जाते है | Character types को एक character store करने के लिए use किया जाता है। String ये immutable data type है |

Source Code :





str1 = "Hello Friends"
str2 = "Welcome to Education Point"

print(str1)
print(str2)



 

Output :




Hello Friends
Welcome to Education Point


 

ज्यादातर Programming languages में string को index में print किया जाता है उसी प्रकार से Python में भी string को indexes से print किया जाता है | string के सबसे पहले character को index '0' से शुरू होती है और string के सबसे आखिरी index '-1' होती है |

Source Code :




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


 


List Data Type in Python

Python के list data type में एक से ज्यादा items होते है | हर एक item को comma(,) से seperate किया जाता है | list के सभी items को square bracket([]) के अन्दर close किये जाता है |
List ये एक compound data type है जिसमे किसी भी data types के items लिए जा सकते है | list ये एक mutable data type है | इन data type के items की values change की जा सकती है |

Source Code :






list = [1, "Hello", 5.6, (1, "Hii")]

for i in list:
    print(i)



 

Output :




1
Hello
5.6
(1, 'Hii')


 


Tuple Data Type in Python


Python के list data type में एक से ज्यादा items होते है | ये list data type के जैसे ही होता है | हर एक item को comma(,) से seperate किया जाता है | Tuple के सभी items को parenthesis(()) के अन्दर close किये जाता है |
Tuple ये एक compound data type है जिसमे किसी भी data types के items लिए जा सकते है | list ये एक immutable data type है | इन data type के items की values change नहीं की जा सकती है |


Source Code :




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')
Traceback (most recent call last):
    tuple[0] = 3  #trying to changing 0th index
TypeError: 'tuple' object does not support item assignment


 


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 है |

Source Code :




dict = {1:"H", 5:"e", 7:"l", 8:"l", 9:"o"}

print(dict[5])
print(dict[9])
 

Output :



e
o


 


Set Data Type in Python



Set Data Type ये items का unordered collection होता है | set में दिए हुआ हर एक item नया होता है | अगर duplicate item मिल जाता है तो उसे remove किया जाता है | set data type के items को curly braces({}}) के अन्दर लिखा जाता है |

Source Code :




set1 = {"satish", "ajay", "shubham"}
for i in set1:
    print(i)
    
set2 = {3, 5, 8, 7, 1, 3}
for j in set2:
     print(j)
 

Output :


satish
ajay
shubham
1
3
5
7

  
Previous
Next Post »

Quote

"Educationists should build the capacities of the spirit of inquiry, creativity, entrepreneurial and moral leadership among students and become their role model."

Dr. Abdual Kalam