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

  

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