SlideShare a Scribd company logo
Data Types
What are data types?
O A data type is a classification of data which tells
the compiler or interpreter how the programmer
intends to use the data.
O Every value in Python has a data type. Since
everything is an object in Python programming,
data types are actually classes and variables are
instance (object) of these classes.
Python allows several data types
O Int
O Float
O Complex
O bool
O Strings
O Bytes
O Byte array
O List
O Tuple
O range
O Set
O Frozen set
O Dictionary
O None
Data Types
SetsNumeric Sequence Mapping
int float Complex
bool
Str Bytes Byte array List Tuple
Set Frozen set
Dictionary
Python's data types can be grouped
into several classes
Range
Fundamental data Types
O The first five data types i.e., int, float, complex,
bool and str are in-built data types or standard
data types.
O All fundamental data types are immutable.
O Immutable means can’t modify.
O Mutable means can be modified.
Integer data type
Integer data type
O To hold integral values i.e., whole number
e.g., 123, 435.
O 4 ways to represent
O Decimal form (x = 10)
O Binary form (x = 0b10)
O Octal form (x = 0o75)
O Hexadecimal form (x = 4F)
Example
Python provide output in the decimal form.
What if we want output in binary or octal or hex?
Base conversion
O Some built-in function are used
O bin(x)
O Oct(x)
O Hex(x)
Decimal, octal, hex
e.g. bin(15) = 1111
Decimal, binary, hex
Decimal, binary, octal
e.g. hex(10) = 0xa
Float Data Type
Floating data type
O E.g., 123.456
O There is no way to specify float value in
binary, octal or hexadecimal.
O a = 0x123.45 will through an error
Cont....
Exponential form
f = 1.2e3
It means 1.2 * 10^3 = 1.2 *1000 = 1200
Complex Data Type
Complex data type
O Format is a + bj
a is called real part
b is called imaginary part
j² = -1
O Use to develop mathematical application or
scientific application.
O 10 + 20j
Only j is valid
10 + 29i will through error
Cont...
a + bj
Real value
Can be int, float
Can only be in decimal form
2, 2.3
binary octal Hexa decimal
Operation on complex
Real/imag are not function
they are in built attributes to
get real or imaginary value
Boolean Data Type
Bool data type
O To represent logical values.
O Allowed values of Bool data types
O True
O False Compulsorily ‘T’ & ‘F’ are capital
True = 1 & False = 0
True & False are resented as 1 & 0
respectively
Str Data Type
Str data type
O Any sequence of character known as string.
O Enclosed in quotes of any type --- single
quotation, double quotation and triple
quotation (for multiple lines).
O Python strings are immutable(will be
discussed).
Should be in quotes
Output in single quote only, even
when input is given in double quote
Triple quote for multiline
In shell it shows n as line break
Bytes data type
Bytes data type
O Represent a group of byte numbers just like an array.
O Every value should be in the range of 0 to 256
O Bytes data type is immutable.
Bytearray data type
Bytearray data type
O Same as bytes data type, the only difference is
bytearray is mutable
immutable
mutable
List data type
List data type
O Represents a group of comma-separated values of any
data type between square brackets.
O Duplication is allowed.
O Lists are mutable i.e., they can be modified.
Tuples data type
Tuples data type
O Tuples are represented as group of comma-separated
values of any data type within parenthesis.
O Tuples are same as lists but tuples are immutable.
Accessing element
Modification is not allowed since tuples are immutable
Range data type
Range data type
O Represent a sequence of values.
O Immutable
O Can be represented by different forms
O Form-1 → with one argument
O E.g.: range(x)→represent values from 0 to (x-1)
O Always Starts from 0
O Form-2 → with two argument
O E.g.: range(x, y)→represent values from x to (y-1)
O Starts from x.
O Form-3 → with three argument
O E.g.: range(x, y, z)→represent values from x to (y-1) with
difference of z. Technically word for z is step.
x, y, z that is argument of range always be in integral value
Form-1 [with one argument]
Modification is not allowed (immutable)
Form-2 [with two argument]
Form-3 [with three argument]
Sets data type
Set data type
O Difference between list and set
O In list the order is preserved (important) and duplication is
allowed.
O In sets, it don’t worry about order and don’t allow duplicate
O Set is an unordered collection of unique items. Set is
defined by values separated by comma inside braces { }.
Items in a set are not ordered.
O Sets are mutable (i.e., modifiable)
O Heterogeneous objects are allowed
• Indexing or slice operator is not allowed since there is no
guarantee in sets that which element is at first position or
which at second bcuz order is not preserved
Frozenset data type
frozenset data type
O Exactly same as set data type except it is
immutable
Dictionary data type
dict data type
O Till yet we have studied about
bytes, bytearray, list, tuple, set, frozenset, range
A group of individual elements/objects, there is
no relation between them.
List, set etc....
Individual objects
What if I want some relation between objects like
Roll no → name (relation between roll no. and name of stu.)
Word → meaning (relation between word and its meaning)
Cont...
O Dictionary is collection of entries in which each entry contains a
key and a corresponding value.
O Duplication is keys are not allowed but values can be duplicate
O Represented as d = {100: ‘john’, 200: ‘smith’}
O Key and values can be heterogeneous
O d = { } #an empty dictionary then what about empty set?
O Empty set can be represented as: s = set()
100 John
200 smith
Key Value
key value
Cont...
Adding elements to dictionary
O Dictionary is mutable so we can allowed to add or remove objects.
Old value(john) replaced by new value
None data type
None data type
O None means nothing or no value associated.
Data type
Immutable Mutable
Numbers Strings Tuples
List Set Dictionary
Python data type classified into:
Class Immutable? Mutable?
Int 
Float 
Complex 
Bool 
Str 
Bytes 
Bytearray 
Range 
List 
Tuple 
Set 
Frozenset 
Dictionary 
Ad

More Related Content

What's hot (20)

Python variables and data types.pptx
Python variables and data types.pptxPython variables and data types.pptx
Python variables and data types.pptx
AkshayAggarwal79
 
Python : Data Types
Python : Data TypesPython : Data Types
Python : Data Types
Emertxe Information Technologies Pvt Ltd
 
Variables in python
Variables in pythonVariables in python
Variables in python
Jaya Kumari
 
Python strings
Python stringsPython strings
Python strings
Mohammed Sikander
 
Functions in python
Functions in pythonFunctions in python
Functions in python
colorsof
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
eShikshak
 
Python programming : Strings
Python programming : StringsPython programming : Strings
Python programming : Strings
Emertxe Information Technologies Pvt Ltd
 
Python libraries
Python librariesPython libraries
Python libraries
Prof. Dr. K. Adisesha
 
Python List.ppt
Python List.pptPython List.ppt
Python List.ppt
T PRIYA
 
Strings in Python
Strings in PythonStrings in Python
Strings in Python
nitamhaske
 
Python Modules
Python ModulesPython Modules
Python Modules
Nitin Reddy Katkam
 
Values and Data types in python
Values and Data types in pythonValues and Data types in python
Values and Data types in python
Jothi Thilaga P
 
Python Datatypes by SujithKumar
Python Datatypes by SujithKumarPython Datatypes by SujithKumar
Python Datatypes by SujithKumar
Sujith Kumar
 
Python ppt
Python pptPython ppt
Python ppt
Mohita Pandey
 
Unit 9. Structure and Unions
Unit 9. Structure and UnionsUnit 9. Structure and Unions
Unit 9. Structure and Unions
Ashim Lamichhane
 
String Manipulation in Python
String Manipulation in PythonString Manipulation in Python
String Manipulation in Python
Pooja B S
 
Python recursion
Python recursionPython recursion
Python recursion
Prof. Dr. K. Adisesha
 
Modules in Python Programming
Modules in Python ProgrammingModules in Python Programming
Modules in Python Programming
sambitmandal
 
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Edureka!
 
Python
PythonPython
Python
Aashish Jain
 

Similar to Python-03| Data types (20)

Python data type
Python data typePython data type
Python data type
nuripatidar
 
Data Types In Python.pptx
Data Types In Python.pptxData Types In Python.pptx
Data Types In Python.pptx
YatharthChaudhary5
 
E-Notes_3720_Content_Document_20250107032323PM.pdf
E-Notes_3720_Content_Document_20250107032323PM.pdfE-Notes_3720_Content_Document_20250107032323PM.pdf
E-Notes_3720_Content_Document_20250107032323PM.pdf
aayushihirpara297
 
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
AliKhokhar33
 
4. Data Handling computer shcience pdf s
4. Data Handling computer shcience pdf s4. Data Handling computer shcience pdf s
4. Data Handling computer shcience pdf s
TonyTech2
 
Computer programming 2 Lesson 5
Computer programming 2  Lesson 5Computer programming 2  Lesson 5
Computer programming 2 Lesson 5
MLG College of Learning, Inc
 
Chapter - 2.pptx
Chapter - 2.pptxChapter - 2.pptx
Chapter - 2.pptx
MikialeTesfamariam
 
The Datatypes Concept in Core Python.pptx
The Datatypes Concept in Core Python.pptxThe Datatypes Concept in Core Python.pptx
The Datatypes Concept in Core Python.pptx
Kavitha713564
 
6031be43a4cf6255acb550cb0c1cf55e.pdf
6031be43a4cf6255acb550cb0c1cf55e.pdf6031be43a4cf6255acb550cb0c1cf55e.pdf
6031be43a4cf6255acb550cb0c1cf55e.pdf
BhavnaSharma423689
 
Data handling CBSE PYTHON CLASS 11
Data handling CBSE PYTHON CLASS 11Data handling CBSE PYTHON CLASS 11
Data handling CBSE PYTHON CLASS 11
chinthala Vijaya Kumar
 
009 Data Handling .pptx
009 Data Handling .pptx009 Data Handling .pptx
009 Data Handling .pptx
ssuser6c66f3
 
Presentation on python data type
Presentation on python data typePresentation on python data type
Presentation on python data type
swati kushwaha
 
Data types in python lecture (2)
Data types in python lecture (2)Data types in python lecture (2)
Data types in python lecture (2)
Ali ٍSattar
 
Python Collections
Python CollectionsPython Collections
Python Collections
sachingarg0
 
Datatypes in Python.pdf
Datatypes in Python.pdfDatatypes in Python.pdf
Datatypes in Python.pdf
king931283
 
Chapter 2-Programming Basics and Arrays.pptx Chapter 2-Programming Basics and...
Chapter 2-Programming Basics and Arrays.pptx Chapter 2-Programming Basics and...Chapter 2-Programming Basics and Arrays.pptx Chapter 2-Programming Basics and...
Chapter 2-Programming Basics and Arrays.pptx Chapter 2-Programming Basics and...
YosefNigussie2
 
COMPUTER SCIENCE SUPPORT MATERIAL CLASS 12.pdf
COMPUTER SCIENCE SUPPORT MATERIAL CLASS 12.pdfCOMPUTER SCIENCE SUPPORT MATERIAL CLASS 12.pdf
COMPUTER SCIENCE SUPPORT MATERIAL CLASS 12.pdf
rajkumar2792005
 
data typesppt.pptxcccccccccccccccccccccccccccccccccccccccccccccc
data typesppt.pptxccccccccccccccccccccccccccccccccccccccccccccccdata typesppt.pptxcccccccccccccccccccccccccccccccccccccccccccccc
data typesppt.pptxcccccccccccccccccccccccccccccccccccccccccccccc
rajpalyadav13052024
 
Python slide.1
Python slide.1Python slide.1
Python slide.1
Aswin Krishnamoorthy
 
data type of pythonpython pytohn datagsdkghmkedhm,fdlbm
data type of pythonpython pytohn datagsdkghmkedhm,fdlbmdata type of pythonpython pytohn datagsdkghmkedhm,fdlbm
data type of pythonpython pytohn datagsdkghmkedhm,fdlbm
dibyashakti10
 
Python data type
Python data typePython data type
Python data type
nuripatidar
 
E-Notes_3720_Content_Document_20250107032323PM.pdf
E-Notes_3720_Content_Document_20250107032323PM.pdfE-Notes_3720_Content_Document_20250107032323PM.pdf
E-Notes_3720_Content_Document_20250107032323PM.pdf
aayushihirpara297
 
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
AliKhokhar33
 
4. Data Handling computer shcience pdf s
4. Data Handling computer shcience pdf s4. Data Handling computer shcience pdf s
4. Data Handling computer shcience pdf s
TonyTech2
 
The Datatypes Concept in Core Python.pptx
The Datatypes Concept in Core Python.pptxThe Datatypes Concept in Core Python.pptx
The Datatypes Concept in Core Python.pptx
Kavitha713564
 
6031be43a4cf6255acb550cb0c1cf55e.pdf
6031be43a4cf6255acb550cb0c1cf55e.pdf6031be43a4cf6255acb550cb0c1cf55e.pdf
6031be43a4cf6255acb550cb0c1cf55e.pdf
BhavnaSharma423689
 
009 Data Handling .pptx
009 Data Handling .pptx009 Data Handling .pptx
009 Data Handling .pptx
ssuser6c66f3
 
Presentation on python data type
Presentation on python data typePresentation on python data type
Presentation on python data type
swati kushwaha
 
Data types in python lecture (2)
Data types in python lecture (2)Data types in python lecture (2)
Data types in python lecture (2)
Ali ٍSattar
 
Python Collections
Python CollectionsPython Collections
Python Collections
sachingarg0
 
Datatypes in Python.pdf
Datatypes in Python.pdfDatatypes in Python.pdf
Datatypes in Python.pdf
king931283
 
Chapter 2-Programming Basics and Arrays.pptx Chapter 2-Programming Basics and...
Chapter 2-Programming Basics and Arrays.pptx Chapter 2-Programming Basics and...Chapter 2-Programming Basics and Arrays.pptx Chapter 2-Programming Basics and...
Chapter 2-Programming Basics and Arrays.pptx Chapter 2-Programming Basics and...
YosefNigussie2
 
COMPUTER SCIENCE SUPPORT MATERIAL CLASS 12.pdf
COMPUTER SCIENCE SUPPORT MATERIAL CLASS 12.pdfCOMPUTER SCIENCE SUPPORT MATERIAL CLASS 12.pdf
COMPUTER SCIENCE SUPPORT MATERIAL CLASS 12.pdf
rajkumar2792005
 
data typesppt.pptxcccccccccccccccccccccccccccccccccccccccccccccc
data typesppt.pptxccccccccccccccccccccccccccccccccccccccccccccccdata typesppt.pptxcccccccccccccccccccccccccccccccccccccccccccccc
data typesppt.pptxcccccccccccccccccccccccccccccccccccccccccccccc
rajpalyadav13052024
 
data type of pythonpython pytohn datagsdkghmkedhm,fdlbm
data type of pythonpython pytohn datagsdkghmkedhm,fdlbmdata type of pythonpython pytohn datagsdkghmkedhm,fdlbm
data type of pythonpython pytohn datagsdkghmkedhm,fdlbm
dibyashakti10
 
Ad

More from Mohd Sajjad (6)

Python-04| Fundamental data types vs immutability
Python-04| Fundamental data types vs immutabilityPython-04| Fundamental data types vs immutability
Python-04| Fundamental data types vs immutability
Mohd Sajjad
 
Python-02| Input, Output & Import
Python-02| Input, Output & ImportPython-02| Input, Output & Import
Python-02| Input, Output & Import
Mohd Sajjad
 
Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| Fundamentals
Mohd Sajjad
 
Python-00 | Introduction and installing
Python-00 | Introduction and installingPython-00 | Introduction and installing
Python-00 | Introduction and installing
Mohd Sajjad
 
Secure your folder with password/without any software
Secure your folder with password/without any softwareSecure your folder with password/without any software
Secure your folder with password/without any software
Mohd Sajjad
 
SNMP Protocol
SNMP ProtocolSNMP Protocol
SNMP Protocol
Mohd Sajjad
 
Python-04| Fundamental data types vs immutability
Python-04| Fundamental data types vs immutabilityPython-04| Fundamental data types vs immutability
Python-04| Fundamental data types vs immutability
Mohd Sajjad
 
Python-02| Input, Output & Import
Python-02| Input, Output & ImportPython-02| Input, Output & Import
Python-02| Input, Output & Import
Mohd Sajjad
 
Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| Fundamentals
Mohd Sajjad
 
Python-00 | Introduction and installing
Python-00 | Introduction and installingPython-00 | Introduction and installing
Python-00 | Introduction and installing
Mohd Sajjad
 
Secure your folder with password/without any software
Secure your folder with password/without any softwareSecure your folder with password/without any software
Secure your folder with password/without any software
Mohd Sajjad
 
Ad

Recently uploaded (20)

E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
The History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptxThe History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
*"The Segmented Blueprint: Unlocking Insect Body Architecture"*.pptx
*"The Segmented Blueprint: Unlocking Insect Body Architecture"*.pptx*"The Segmented Blueprint: Unlocking Insect Body Architecture"*.pptx
*"The Segmented Blueprint: Unlocking Insect Body Architecture"*.pptx
Arshad Shaikh
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Association for Project Management
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast BrooklynBridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
i4jd41bk
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM Mia eStudios
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
*"The Segmented Blueprint: Unlocking Insect Body Architecture"*.pptx
*"The Segmented Blueprint: Unlocking Insect Body Architecture"*.pptx*"The Segmented Blueprint: Unlocking Insect Body Architecture"*.pptx
*"The Segmented Blueprint: Unlocking Insect Body Architecture"*.pptx
Arshad Shaikh
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Association for Project Management
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast BrooklynBridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
i4jd41bk
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM Mia eStudios
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 

Python-03| Data types

  • 2. What are data types? O A data type is a classification of data which tells the compiler or interpreter how the programmer intends to use the data. O Every value in Python has a data type. Since everything is an object in Python programming, data types are actually classes and variables are instance (object) of these classes.
  • 3. Python allows several data types O Int O Float O Complex O bool O Strings O Bytes O Byte array O List O Tuple O range O Set O Frozen set O Dictionary O None
  • 4. Data Types SetsNumeric Sequence Mapping int float Complex bool Str Bytes Byte array List Tuple Set Frozen set Dictionary Python's data types can be grouped into several classes Range
  • 5. Fundamental data Types O The first five data types i.e., int, float, complex, bool and str are in-built data types or standard data types. O All fundamental data types are immutable. O Immutable means can’t modify. O Mutable means can be modified.
  • 7. Integer data type O To hold integral values i.e., whole number e.g., 123, 435. O 4 ways to represent O Decimal form (x = 10) O Binary form (x = 0b10) O Octal form (x = 0o75) O Hexadecimal form (x = 4F)
  • 8. Example Python provide output in the decimal form. What if we want output in binary or octal or hex?
  • 9. Base conversion O Some built-in function are used O bin(x) O Oct(x) O Hex(x) Decimal, octal, hex e.g. bin(15) = 1111 Decimal, binary, hex Decimal, binary, octal e.g. hex(10) = 0xa
  • 11. Floating data type O E.g., 123.456 O There is no way to specify float value in binary, octal or hexadecimal. O a = 0x123.45 will through an error
  • 12. Cont.... Exponential form f = 1.2e3 It means 1.2 * 10^3 = 1.2 *1000 = 1200
  • 14. Complex data type O Format is a + bj a is called real part b is called imaginary part j² = -1 O Use to develop mathematical application or scientific application. O 10 + 20j Only j is valid 10 + 29i will through error
  • 15. Cont... a + bj Real value Can be int, float Can only be in decimal form 2, 2.3 binary octal Hexa decimal
  • 16. Operation on complex Real/imag are not function they are in built attributes to get real or imaginary value
  • 18. Bool data type O To represent logical values. O Allowed values of Bool data types O True O False Compulsorily ‘T’ & ‘F’ are capital
  • 19. True = 1 & False = 0 True & False are resented as 1 & 0 respectively
  • 21. Str data type O Any sequence of character known as string. O Enclosed in quotes of any type --- single quotation, double quotation and triple quotation (for multiple lines). O Python strings are immutable(will be discussed).
  • 22. Should be in quotes Output in single quote only, even when input is given in double quote Triple quote for multiline In shell it shows n as line break
  • 24. Bytes data type O Represent a group of byte numbers just like an array. O Every value should be in the range of 0 to 256 O Bytes data type is immutable.
  • 26. Bytearray data type O Same as bytes data type, the only difference is bytearray is mutable immutable mutable
  • 28. List data type O Represents a group of comma-separated values of any data type between square brackets. O Duplication is allowed. O Lists are mutable i.e., they can be modified.
  • 30. Tuples data type O Tuples are represented as group of comma-separated values of any data type within parenthesis. O Tuples are same as lists but tuples are immutable. Accessing element Modification is not allowed since tuples are immutable
  • 32. Range data type O Represent a sequence of values. O Immutable O Can be represented by different forms O Form-1 → with one argument O E.g.: range(x)→represent values from 0 to (x-1) O Always Starts from 0 O Form-2 → with two argument O E.g.: range(x, y)→represent values from x to (y-1) O Starts from x. O Form-3 → with three argument O E.g.: range(x, y, z)→represent values from x to (y-1) with difference of z. Technically word for z is step. x, y, z that is argument of range always be in integral value
  • 33. Form-1 [with one argument] Modification is not allowed (immutable)
  • 34. Form-2 [with two argument]
  • 35. Form-3 [with three argument]
  • 37. Set data type O Difference between list and set O In list the order is preserved (important) and duplication is allowed. O In sets, it don’t worry about order and don’t allow duplicate O Set is an unordered collection of unique items. Set is defined by values separated by comma inside braces { }. Items in a set are not ordered. O Sets are mutable (i.e., modifiable) O Heterogeneous objects are allowed
  • 38. • Indexing or slice operator is not allowed since there is no guarantee in sets that which element is at first position or which at second bcuz order is not preserved
  • 40. frozenset data type O Exactly same as set data type except it is immutable
  • 42. dict data type O Till yet we have studied about bytes, bytearray, list, tuple, set, frozenset, range A group of individual elements/objects, there is no relation between them. List, set etc.... Individual objects What if I want some relation between objects like Roll no → name (relation between roll no. and name of stu.) Word → meaning (relation between word and its meaning)
  • 43. Cont... O Dictionary is collection of entries in which each entry contains a key and a corresponding value. O Duplication is keys are not allowed but values can be duplicate O Represented as d = {100: ‘john’, 200: ‘smith’} O Key and values can be heterogeneous O d = { } #an empty dictionary then what about empty set? O Empty set can be represented as: s = set() 100 John 200 smith Key Value key value
  • 45. Adding elements to dictionary O Dictionary is mutable so we can allowed to add or remove objects. Old value(john) replaced by new value
  • 47. None data type O None means nothing or no value associated.
  • 48. Data type Immutable Mutable Numbers Strings Tuples List Set Dictionary Python data type classified into:
  • 49. Class Immutable? Mutable? Int  Float  Complex  Bool  Str  Bytes  Bytearray  Range  List  Tuple  Set  Frozenset  Dictionary 
  翻译: