SlideShare a Scribd company logo
1 of 24
Datatypes
In Python
Mrs.N.Kavitha
Head,Department of Computer Science,
E.M.G.Yadava Women’s College
Madurai-14.
Content
Introduction
Types of datatype
Numeric
Set
Boolean
None
Sequence
Mapping
Introduction
 Data types are the classification or categorization of data items. It
represents the kind of value that tells what operations can be performed on
a particular data. Since everything is an object in Python programming
data types are actually classes and variables are instances (object) of these
classes.
 To define the values ​​of various data types and check their data types
we use the type() function.
Types of Datatype
Numeric
 The numeric data type in Python represents the data that has a numeric value. A
numeric value can be an integer , float or complex.
 Integers – This value is represented by int class. It contains positive or negative
whole numbers (without fractions or decimals). In Python, there is no limit to
how long an integer value can be.
 Float – This value is represented by the float class. It is a real number with a
floating-point representation. It is specified by a decimal point. Optionally, the
character e or E followed by a positive or negative integer may be appended to
specify scientific notation.
 Complex Numbers – Complex number is represented by a complex class. It is
specified as (real part) + (imaginary part) j.
For Example
a = 5
print("Type of a: ", type(a))
b = 5.0
print("nType of b: ", type(b))
c = 2 + 4j
print("nType of c: ", type(c))
Output
Type of a: <class ‘int’>
Type of b: <class ‘float’>
Type of c: <class ‘complex’>
Sets
 A set is an unordered collection of elements much like a set in Mathematics.
 The order of elements is not maintained in the sets. It means the elements may
not appear in the same order as they are entered into the set.
 A set does not accept duplicate elements.
 There are two sub types in sets:
set datatype
frozen set datatype
Set datatypes
 To create a set , we should enter the elements separated by commas inside
curly braces{}.
 For example
s={12,13,12,14,15} Output
print(s) {14,12,13,15}
 Here the set ‘s’ is not maintaining the order of the elements.
 we repeated the element 12 in the set, but it stored only one 12.
Frozenset Datatype
 The frozenset datatype is same as the set datatype.
 The main difference is that the elements in the set datatype can be modified;
the elements of frozen set cannot be modified.
 For example
Output
s={50,60,70,80,90} {80,90,50,60,70}
print(s)
fs=frozenset(s) ({80,90,50,60,70})
print(fs)
fs= frozenset(abcdefg) ({ ‘e’, ’g’, ’f’ , ’d’, ’a’ , ’c’, ’b’})
print(fs)
Boolean
 The bool datatype in python represents Boolean values.
 There are only two Boolean values True or False that can be represented by
this datatype.
 Python internally represents True as 1 and False as 0. A blank string like “” is
also represented as False.
 For example
a=10 Output
b=20 Hello
if (a<b):
print(‘Hello’)
None
 In python, the ‘None’ datatype represents an object that does not contain any
values.
 In languages like Java, it is called ‘Null’ object . But in Python, it is called ‘None’
object.
 One of the uses of ‘None’ is that it is used inside a function as a default value of
the arguments.
 When calling the function, if no value is passed , then the default value will be
taken as ‘None’.
Sequence
 A Sequence represents a group of elements or item.
 For example , a group of integer numbers will form a sequence.
 There are six types of sequences in Python:
str
bytes
bytearray
list
tuple
range
str
 In Python , str represents string datatype.
 A string is represented by a group of characters.
 String are enclosed in single quotes ’’ or double quotes “”.
 For example
Output
str=“Hai” Hai
str=‘Hi’ Hi
For Example
s=‘Lets learn python’ Output
print(s) Lets learn python
print(s[0]) L
print(s[0:5]) Lets
print(s[12: ]) python
print(s[-2]) o
Bytes
 The bytes represents a group of byte numbers just like an array does.
 A byte number is any positive integer from 0 to 255
 Bytes array can store numbers in the range from 0 to 255 and it cannot even
store negative numbers.
 For example
elements =[10,20,0,40,15] Output
x=bytes(elements) 10
print(x[0])
Bytearray
 The bytearray datatype is similar to bytes datatype.
 The difference is that the bytes type array cannot be modified but the
bytearray type array can be modified.
 For example
elements=[10,20,0,40,15] Output
x=bytearray(elements)
print (x[0]) 10
x[0]=88
x[1]=99 88,99,0,40,50
print(x)
List
 A list is a collection of different types of datatype values or items.
 Since Python lists are mutable, we can change their elements after forming.
 The comma (,) and the square brackets [enclose the List's items] serve as
separators.
 Lists are created using square brackets.
 For example
list = ["apple", "banana", "cherry"]
print(list)
For Example
list1 = [1, 2, "Python", "Program", 15.9] Output
list2 = ["Amy", "Ryan", "Henry", "Emma"]
[1, 2,”Python”, “Program”, 15.9]
print(list1) [“Amy ”, ”Ryan ”,” Henry” ,” Emma”]
print(list2)
2
print(list1[1]) Amy
print(list2[0])
Tuple
 A tuple is a collection of objects which ordered and immutable.
 Tuples are sequences, just like lists. The differences between tuples and
lists are, the tuples cannot be changed and the lists can be change.
 Unlike lists and tuples use parentheses, whereas lists use square
brackets.
 Tuples are immutable which means you cannot update or change the
values of tuple elements. You are able to take portions of existing tuples
to create new tuples
For Example
tup1 = ('physics', 'chemistry', 1997, 2000) Output
tup2 = (1, 2, 3, 4, 5, 6, 7 )
print (tup1[0]) physics
print (tup2[1:5]) [2, 3, 4, 5]
Range
 Python range() is an in-built function in Python which returns a sequence of
numbers starting from 0 and increments to 1 until it reaches a specified number.
 We use range() function with for and while loop to generate a sequence of
numbers. Following is the syntax of the function:
 range(start, stop, step)
 Here is the description of the parameters used:
start: Integer number to specify starting position, (Its optional, Default: 0)
stop: Integer number to specify starting position (It's mandatory)
step: Integer number to specify increment, (Its optional, Default: 1)
For Example
for i in range(5): Output
print(i) 0 1 2 3 4
for i in range(1, 5):
print(i) 1 2 3 4
for i in range(1, 5, 2):
print(i) 1 3
Mapping
 Python Dictionary is an unordered sequence of data of key-value pair
form. It is similar to the hash table type.
 Dictionaries are written within curly braces in the form {key : value} .
 It is very useful to retrieve data in an optimized way among a large
amount of data.
dict={001: RDJ}
Key Value
For Example
a = {1:“RDJ", 2:“JD“ , "age":33} Output
print(a[1]) RDJ
print(a[2]) JD
print(a["age"]) 33

More Related Content

Similar to The Datatypes Concept in Core Python.pptx

Python Data Types.pdf
Python Data Types.pdfPython Data Types.pdf
Python Data Types.pdfNehaSpillai1
 
Python Data Types (1).pdf
Python Data Types (1).pdfPython Data Types (1).pdf
Python Data Types (1).pdfNehaSpillai1
 
Python Datatypes by SujithKumar
Python Datatypes by SujithKumarPython Datatypes by SujithKumar
Python Datatypes by SujithKumarSujith Kumar
 
Python data type
Python data typePython data type
Python data typeJaya Kumari
 
Module 4- Arrays and Strings
Module 4- Arrays and StringsModule 4- Arrays and Strings
Module 4- Arrays and Stringsnikshaikh786
 
13- Data and Its Types presentation kafss
13- Data and Its Types presentation kafss13- Data and Its Types presentation kafss
13- Data and Its Types presentation kafssAliKhokhar33
 
Python Collections
Python CollectionsPython Collections
Python Collectionssachingarg0
 
Python - Data Collection
Python - Data CollectionPython - Data Collection
Python - Data CollectionJoseTanJr
 
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfHomework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfaroraopticals15
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxAbhishek Tirkey
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxGauravPandey43518
 
Array assignment
Array assignmentArray assignment
Array assignmentAhmad Kamal
 
RANDOMISATION-NUMERICAL METHODS FOR ENGINEERING.pptx
RANDOMISATION-NUMERICAL METHODS  FOR ENGINEERING.pptxRANDOMISATION-NUMERICAL METHODS  FOR ENGINEERING.pptx
RANDOMISATION-NUMERICAL METHODS FOR ENGINEERING.pptxOut Cast
 
Data Type In Python.pptx
Data Type In Python.pptxData Type In Python.pptx
Data Type In Python.pptxhothyfa
 
Data Structures in Python
Data Structures in PythonData Structures in Python
Data Structures in PythonDevashish Kumar
 

Similar to The Datatypes Concept in Core Python.pptx (20)

Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
 
Python Data Types.pdf
Python Data Types.pdfPython Data Types.pdf
Python Data Types.pdf
 
Python Data Types (1).pdf
Python Data Types (1).pdfPython Data Types (1).pdf
Python Data Types (1).pdf
 
Python Datatypes by SujithKumar
Python Datatypes by SujithKumarPython Datatypes by SujithKumar
Python Datatypes by SujithKumar
 
Python data type
Python data typePython data type
Python data type
 
Module 4- Arrays and Strings
Module 4- Arrays and StringsModule 4- Arrays and Strings
Module 4- Arrays and Strings
 
13- Data and Its Types presentation kafss
13- Data and Its Types presentation kafss13- Data and Its Types presentation kafss
13- Data and Its Types presentation kafss
 
Array
ArrayArray
Array
 
Python Collections
Python CollectionsPython Collections
Python Collections
 
Python - Data Collection
Python - Data CollectionPython - Data Collection
Python - Data Collection
 
Chapter - 2.pptx
Chapter - 2.pptxChapter - 2.pptx
Chapter - 2.pptx
 
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfHomework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdf
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
 
Arrays
ArraysArrays
Arrays
 
Array assignment
Array assignmentArray assignment
Array assignment
 
Standard data-types-in-py
Standard data-types-in-pyStandard data-types-in-py
Standard data-types-in-py
 
RANDOMISATION-NUMERICAL METHODS FOR ENGINEERING.pptx
RANDOMISATION-NUMERICAL METHODS  FOR ENGINEERING.pptxRANDOMISATION-NUMERICAL METHODS  FOR ENGINEERING.pptx
RANDOMISATION-NUMERICAL METHODS FOR ENGINEERING.pptx
 
Data Type In Python.pptx
Data Type In Python.pptxData Type In Python.pptx
Data Type In Python.pptx
 
Data Structures in Python
Data Structures in PythonData Structures in Python
Data Structures in Python
 

More from Kavitha713564

THE PACKAGES CONCEPT IN JAVA PROGRAMMING.pptx
THE PACKAGES CONCEPT  IN JAVA PROGRAMMING.pptxTHE PACKAGES CONCEPT  IN JAVA PROGRAMMING.pptx
THE PACKAGES CONCEPT IN JAVA PROGRAMMING.pptxKavitha713564
 
The Java Server Page in Java Concept.pptx
The Java Server Page in Java Concept.pptxThe Java Server Page in Java Concept.pptx
The Java Server Page in Java Concept.pptxKavitha713564
 
Programming in python in detail concept .pptx
Programming in python in detail concept .pptxProgramming in python in detail concept .pptx
Programming in python in detail concept .pptxKavitha713564
 
The Input Statement in Core Python .pptx
The Input Statement in Core Python .pptxThe Input Statement in Core Python .pptx
The Input Statement in Core Python .pptxKavitha713564
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in javaKavitha713564
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in javaKavitha713564
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in javaKavitha713564
 
Input output files in java
Input output files in javaInput output files in java
Input output files in javaKavitha713564
 
Arrays,string and vector
Arrays,string and vectorArrays,string and vector
Arrays,string and vectorKavitha713564
 

More from Kavitha713564 (14)

THE PACKAGES CONCEPT IN JAVA PROGRAMMING.pptx
THE PACKAGES CONCEPT  IN JAVA PROGRAMMING.pptxTHE PACKAGES CONCEPT  IN JAVA PROGRAMMING.pptx
THE PACKAGES CONCEPT IN JAVA PROGRAMMING.pptx
 
The Java Server Page in Java Concept.pptx
The Java Server Page in Java Concept.pptxThe Java Server Page in Java Concept.pptx
The Java Server Page in Java Concept.pptx
 
Programming in python in detail concept .pptx
Programming in python in detail concept .pptxProgramming in python in detail concept .pptx
Programming in python in detail concept .pptx
 
The Input Statement in Core Python .pptx
The Input Statement in Core Python .pptxThe Input Statement in Core Python .pptx
The Input Statement in Core Python .pptx
 
Packages in java
Packages in javaPackages in java
Packages in java
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
Applet in java new
Applet in java newApplet in java new
Applet in java new
 
Basic of java
Basic of javaBasic of java
Basic of java
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Input output files in java
Input output files in javaInput output files in java
Input output files in java
 
Arrays,string and vector
Arrays,string and vectorArrays,string and vector
Arrays,string and vector
 

Recently uploaded

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 

Recently uploaded (20)

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 

The Datatypes Concept in Core Python.pptx

  • 1. Datatypes In Python Mrs.N.Kavitha Head,Department of Computer Science, E.M.G.Yadava Women’s College Madurai-14.
  • 3. Introduction  Data types are the classification or categorization of data items. It represents the kind of value that tells what operations can be performed on a particular data. Since everything is an object in Python programming data types are actually classes and variables are instances (object) of these classes.  To define the values ​​of various data types and check their data types we use the type() function.
  • 5. Numeric  The numeric data type in Python represents the data that has a numeric value. A numeric value can be an integer , float or complex.  Integers – This value is represented by int class. It contains positive or negative whole numbers (without fractions or decimals). In Python, there is no limit to how long an integer value can be.  Float – This value is represented by the float class. It is a real number with a floating-point representation. It is specified by a decimal point. Optionally, the character e or E followed by a positive or negative integer may be appended to specify scientific notation.  Complex Numbers – Complex number is represented by a complex class. It is specified as (real part) + (imaginary part) j.
  • 6. For Example a = 5 print("Type of a: ", type(a)) b = 5.0 print("nType of b: ", type(b)) c = 2 + 4j print("nType of c: ", type(c)) Output Type of a: <class ‘int’> Type of b: <class ‘float’> Type of c: <class ‘complex’>
  • 7. Sets  A set is an unordered collection of elements much like a set in Mathematics.  The order of elements is not maintained in the sets. It means the elements may not appear in the same order as they are entered into the set.  A set does not accept duplicate elements.  There are two sub types in sets: set datatype frozen set datatype
  • 8. Set datatypes  To create a set , we should enter the elements separated by commas inside curly braces{}.  For example s={12,13,12,14,15} Output print(s) {14,12,13,15}  Here the set ‘s’ is not maintaining the order of the elements.  we repeated the element 12 in the set, but it stored only one 12.
  • 9. Frozenset Datatype  The frozenset datatype is same as the set datatype.  The main difference is that the elements in the set datatype can be modified; the elements of frozen set cannot be modified.  For example Output s={50,60,70,80,90} {80,90,50,60,70} print(s) fs=frozenset(s) ({80,90,50,60,70}) print(fs) fs= frozenset(abcdefg) ({ ‘e’, ’g’, ’f’ , ’d’, ’a’ , ’c’, ’b’}) print(fs)
  • 10. Boolean  The bool datatype in python represents Boolean values.  There are only two Boolean values True or False that can be represented by this datatype.  Python internally represents True as 1 and False as 0. A blank string like “” is also represented as False.  For example a=10 Output b=20 Hello if (a<b): print(‘Hello’)
  • 11. None  In python, the ‘None’ datatype represents an object that does not contain any values.  In languages like Java, it is called ‘Null’ object . But in Python, it is called ‘None’ object.  One of the uses of ‘None’ is that it is used inside a function as a default value of the arguments.  When calling the function, if no value is passed , then the default value will be taken as ‘None’.
  • 12. Sequence  A Sequence represents a group of elements or item.  For example , a group of integer numbers will form a sequence.  There are six types of sequences in Python: str bytes bytearray list tuple range
  • 13. str  In Python , str represents string datatype.  A string is represented by a group of characters.  String are enclosed in single quotes ’’ or double quotes “”.  For example Output str=“Hai” Hai str=‘Hi’ Hi
  • 14. For Example s=‘Lets learn python’ Output print(s) Lets learn python print(s[0]) L print(s[0:5]) Lets print(s[12: ]) python print(s[-2]) o
  • 15. Bytes  The bytes represents a group of byte numbers just like an array does.  A byte number is any positive integer from 0 to 255  Bytes array can store numbers in the range from 0 to 255 and it cannot even store negative numbers.  For example elements =[10,20,0,40,15] Output x=bytes(elements) 10 print(x[0])
  • 16. Bytearray  The bytearray datatype is similar to bytes datatype.  The difference is that the bytes type array cannot be modified but the bytearray type array can be modified.  For example elements=[10,20,0,40,15] Output x=bytearray(elements) print (x[0]) 10 x[0]=88 x[1]=99 88,99,0,40,50 print(x)
  • 17. List  A list is a collection of different types of datatype values or items.  Since Python lists are mutable, we can change their elements after forming.  The comma (,) and the square brackets [enclose the List's items] serve as separators.  Lists are created using square brackets.  For example list = ["apple", "banana", "cherry"] print(list)
  • 18. For Example list1 = [1, 2, "Python", "Program", 15.9] Output list2 = ["Amy", "Ryan", "Henry", "Emma"] [1, 2,”Python”, “Program”, 15.9] print(list1) [“Amy ”, ”Ryan ”,” Henry” ,” Emma”] print(list2) 2 print(list1[1]) Amy print(list2[0])
  • 19. Tuple  A tuple is a collection of objects which ordered and immutable.  Tuples are sequences, just like lists. The differences between tuples and lists are, the tuples cannot be changed and the lists can be change.  Unlike lists and tuples use parentheses, whereas lists use square brackets.  Tuples are immutable which means you cannot update or change the values of tuple elements. You are able to take portions of existing tuples to create new tuples
  • 20. For Example tup1 = ('physics', 'chemistry', 1997, 2000) Output tup2 = (1, 2, 3, 4, 5, 6, 7 ) print (tup1[0]) physics print (tup2[1:5]) [2, 3, 4, 5]
  • 21. Range  Python range() is an in-built function in Python which returns a sequence of numbers starting from 0 and increments to 1 until it reaches a specified number.  We use range() function with for and while loop to generate a sequence of numbers. Following is the syntax of the function:  range(start, stop, step)  Here is the description of the parameters used: start: Integer number to specify starting position, (Its optional, Default: 0) stop: Integer number to specify starting position (It's mandatory) step: Integer number to specify increment, (Its optional, Default: 1)
  • 22. For Example for i in range(5): Output print(i) 0 1 2 3 4 for i in range(1, 5): print(i) 1 2 3 4 for i in range(1, 5, 2): print(i) 1 3
  • 23. Mapping  Python Dictionary is an unordered sequence of data of key-value pair form. It is similar to the hash table type.  Dictionaries are written within curly braces in the form {key : value} .  It is very useful to retrieve data in an optimized way among a large amount of data. dict={001: RDJ} Key Value
  • 24. For Example a = {1:“RDJ", 2:“JD“ , "age":33} Output print(a[1]) RDJ print(a[2]) JD print(a["age"]) 33