
what is data type in python - data types in python
नमस्कार दोस्तो आज इस आर्टिकल में जानेंगे कि Python में Data Types क्या हैं ? और यह कितने प्रकार के होते हैं ?
Python में variables के अन्दर अलग-अलग types की values store की जाती है जैसे कि किसी variable के अन्दर numeric value तो किसी दूसरे variable के अन्दर alphabetic value store की जाती है, इसे ही 'Data Types' कहा जाता है |
सभी programming language में डाटा टाइप होते हैं |
इसी प्रकार पाइथन में भी कुछ डाटा टाइप (python data types) हैं जो की इस प्रकार हैं |
data type in python
- Number Data Type
- String Data Type
- List Data Type
- Tuple Data Type
- Dictionary Data Type
- Set Data Type
Note : type() function का इस्तेमाल data type check करने के लिए किया जाता है |
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 in python
Integer data type ये normal numeric values होती है | integer numbers को अपूर्णांकित हिस्सा नहीं होता है |
floating-point number data type in python
Floating-point numbers को अपूर्णांकित हिस्सा होता है | Python में floating-point number के लिए कोई मर्यादा नहीं होती है |
complex number data type in python
Complex data type 'a + bj' इस form में होता है इसमे 'a' ये real part होता है और 'b' ये imaginary part होता है |
# यह Integer data type है |
a = 5
b = 12545885
c = 412154986446513513878678541351865465
print(a)
print(b)
print(c)
print(type(a))
print(type(b))
print(type(c))
# यह Floating-point numbers data type है |
a = 5.0
b = 12545885.568444444444445
c = 412154986446513513878678541351865465.4547878541516546845
print(a)
print(b)
print(c)
print(type(a))
print(type(b))
print(type(c))
# यह Complex data type है |
a = 1 + 4j
b = 5 + 4758499j
print(a)
print(b)
print(type(a))
print(type(b))
Output :#Integer data type
5
12545885
412154986446513513878678541351865465
#Floating-point Number Data Type
5.0
12545885.568444444
4.121549864465135e+35
#Complex data type
(1+4j)
(5+4758499j)
what is a string data type
string data type in python
String ये characters का set होता है | characters; letters, numbers या special symbols हो सकते है| Python में single(' ') या double(" ") quotes के अन्दर लिखे जाते है | String ये immutable data type है |
str1 = "Hello World"
str2 = "Hello Friends"
print(str1)
print(str2)
Output :Hello World
Hello Friends
data type string
ज्यादातर Programming languages में string को index में print किया जाता है उसी प्रकार से Python में भी string को indexes से print किया जाता है | string के सबसे पहले character को index '0' से शुरू होती है और string के सबसे आखिरी index '-1' होती है |
list data type in python
Python के list data type में एक से ज्यादा items होते है | हर एक item को comma(,) से separate किया जाता है |
list के सभी items को square bracket([]) के अन्दर close किये जाता है |
List ये एक compound data type है जिसमे किसी भी data types के items लिए जा सकते है | list ये एक mutable data type है | इन data type के items की values change की जा सकती है |
list = [1, "Hello", 5.6, (1, "MAXON")]
for i in list:
print(i)
Output :1
Hello
5.6
(1, 'MAXON')
Tuple Data Type In Python
Python के list data type में एक से ज्यादा items होते है | ये list data type के जैसे ही होता है | हर एक item को comma(,) से separate किया जाता है |Tuple के सभी items को parenthesis(()) के अन्दर close किये जाता है |
Tuple ये एक compound data type है जिसमे किसी भी data types के items लिए जा सकते है | list ये एक immutable data type है | इन data type के items की values change नहीं की जा सकती है |
tuple = (1, "Hello", 5.6, (1, "MAXON"))
for i in tuple:
print(i)
tuple[0] = 3 #trying to changing 0th index
print(tuple[0])
Output :1
Hello
5.6
(1, 'MAXON')
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(:) से separate किया जाता है |
Dictionary के सभी keys और values को curly braces({}) में लिखा जाता है | ये एक immutable data type है |
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({}}) के अन्दर लिखा जाता है |
set1 = {"Maxon", "Puneet", "Kapil"}
for i in set1:
print(i)
set2 = {3, 5, 8, 7, 1, 3}
for j in set2:
print(j)
Output :