SlideShare a Scribd company logo
PythonTutorials
Lecture -2-
By: Ali Sattar
To: Everyone
Contents:
1.What is the data type?
2.The data types in python.
3. MutableVs. Immutable objects?
Data type it is just determine the type of the object in your program. Python will
store that object with it’s type in the memory, also the interpreter needs to check the
status of that object for the operation later. The general from to define any variable of any
data type in python is look like below:
Variable Name = Object
A = 20
So, here A is the variable name and 20 is the object content which is assigned to the
variable, you see now how python deal with the data types.
1.What is the data type?
2.The data types in python
The data types in python can be classified into five categories or classes:
2.1 Boolean.
2.2 Numeric types.
2.3 Sequences.
2.4 Sets.
2.5 Mapping.
2.The data types in python
2.1 Boolean: This type has a two values either: True or False. This type can be used with
decision making statements or where we want to represent the two values.
Ex: T =True
2.2 Numeric types: This category can be classified into four data types: int, float, long
and complex.
Ex: A = 20 ; F = 2.5 ; L = 21321L ; C = 10 + 5j
► For long type now is not working in python 3.x but it was working in python 2.x and we
need to put L in the last. For complex type is just consist of a two parts: Real part and
imaginary part
2.3 Sequences: This category can be classified into four data types: String, bytes, byte array, list
and tuple.
Ex:
S = “Ali Sattar” or S = str(“Hello”)  S is a string type
B1 = b1’A’  b1 is a bytes type, it is like char type in other languages.
B2 = b2’Python’  b2 is another bytes type, but it followed by sequence of letters.
BA = (“Python, Java”, “utf8”)  b is of type bytearray returns a two items only.
L = [‘String’, 24, 2.5, ‘b’]  L is of type list contains multiple items.
T = (‘One’, ‘Two’, ‘Three’)  T is of type tuple, it is similar to list but there is a difference.
2. The data types in python
2.The data type in python
► For bytes data type is look like the char data type but here is expanded with not only
one byte but with a sequence of bytes like you did noticed before in the examples.
► For list it is just a sequences of items started by 0m where list object can contains many
data types for other objects ok. “List is changeable; means can be modified by insert,
update and even delete”.
► For tuple is similar to list but surround it’s items with () instead of []. “Tuple is not
changeable, so you cannot do update, insert and even delete”.
► You can use the method str() to convert any other data type to string type.
► We can use bytearray too if we want to represent a sequence of letters as list.
2.4 Sets: A set is unordered collection of items inside curly braces {}. The object inside
the list is non-changeable but the set can be modified by adding or removing an items.
The set can contain items of different data types, each item inside the set is separated
comma (,) and built in using the method set(). The difference between set and list is
list items can be updated in place while set items are not.
Ex: my_Set = { 100, b’B’, “Ali Sattar”, 20.5, (1, 2, 3) }
► Here as you can see, we created a set of different items and with a different data
types.
2. The data type in python
2.The data type in python
2.5 Mapping: Dictionary is the only data type here, the dictionary is unordered collection
of items (elements) where the items are surrounded by a curly braces too {} like set. Each
item is separated by comma and it has a key: value pair. Dictionary items are changeable
like list and bytearray.
Ex:
Diction1 = { 1: ‘Sunday’, 2: ‘Monday’, 3: ‘Tuesday’ }
Diction2 = { ‘A’: ‘Apple’, ‘B’: ‘Bannana’, ‘C’: ‘Chocolate’ }
Diction3 = { 12: ‘3*4’, 15: ‘3*5’}
3. Mutable vs. Immutable objects
Mutable Object: It is the object in which it’s value can be changed. For example: list,
bytearray, byte and dictionary.
Immutable Object: It is the object in which it’s value cannot be changed. For example:
int, float, str, tuple and set.
Ad

More Related Content

What's hot (20)

Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
Sujith Kumar
 
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
 
Data types in java
Data types in javaData types in java
Data types in java
HarshitaAshwani
 
Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)
PyData
 
Arrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | EdurekaArrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | Edureka
Edureka!
 
Java basics and java variables
Java basics and java variablesJava basics and java variables
Java basics and java variables
Pushpendra Tyagi
 
Set methods in python
Set methods in pythonSet methods in python
Set methods in python
deepalishinkar1
 
Datastructures in python
Datastructures in pythonDatastructures in python
Datastructures in python
hydpy
 
Object oriented programming in python
Object oriented programming in pythonObject oriented programming in python
Object oriented programming in python
baabtra.com - No. 1 supplier of quality freshers
 
Modules in Python Programming
Modules in Python ProgrammingModules in Python Programming
Modules in Python Programming
sambitmandal
 
Python list
Python listPython list
Python list
Mohammed Sikander
 
Sparse matrix and its representation data structure
Sparse matrix and its representation data structureSparse matrix and its representation data structure
Sparse matrix and its representation data structure
Vardhil Patel
 
Array ppt
Array pptArray ppt
Array ppt
Kaushal Mehta
 
Data structures & algorithms lecture 3
Data structures & algorithms lecture 3Data structures & algorithms lecture 3
Data structures & algorithms lecture 3
Poojith Chowdhary
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
KristinaBorooah
 
Object Oriented Programming in Python
Object Oriented Programming in PythonObject Oriented Programming in Python
Object Oriented Programming in Python
Sujith Kumar
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
eShikshak
 
Chapter 15 Lists
Chapter 15 ListsChapter 15 Lists
Chapter 15 Lists
Praveen M Jigajinni
 
Quick sort
Quick sortQuick sort
Quick sort
Dhruv Sabalpara
 
Python OOPs
Python OOPsPython OOPs
Python OOPs
Binay Kumar Ray
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
Sujith Kumar
 
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
 
Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)
PyData
 
Arrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | EdurekaArrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | Edureka
Edureka!
 
Java basics and java variables
Java basics and java variablesJava basics and java variables
Java basics and java variables
Pushpendra Tyagi
 
Datastructures in python
Datastructures in pythonDatastructures in python
Datastructures in python
hydpy
 
Modules in Python Programming
Modules in Python ProgrammingModules in Python Programming
Modules in Python Programming
sambitmandal
 
Sparse matrix and its representation data structure
Sparse matrix and its representation data structureSparse matrix and its representation data structure
Sparse matrix and its representation data structure
Vardhil Patel
 
Data structures & algorithms lecture 3
Data structures & algorithms lecture 3Data structures & algorithms lecture 3
Data structures & algorithms lecture 3
Poojith Chowdhary
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
KristinaBorooah
 
Object Oriented Programming in Python
Object Oriented Programming in PythonObject Oriented Programming in Python
Object Oriented Programming in Python
Sujith Kumar
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
eShikshak
 

Similar to Data types in python lecture (2) (20)

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
 
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
 
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
 
Chapter - 2.pptx
Chapter - 2.pptxChapter - 2.pptx
Chapter - 2.pptx
MikialeTesfamariam
 
Python data type
Python data typePython data type
Python data type
nuripatidar
 
datatypes and its types.pptxgfmnghmghmfgm
datatypes and its types.pptxgfmnghmghmfgmdatatypes and its types.pptxgfmnghmghmfgm
datatypes and its types.pptxgfmnghmghmfgm
dibyashakti10
 
Anton Kasyanov, Introduction to Python, Lecture4
Anton Kasyanov, Introduction to Python, Lecture4Anton Kasyanov, Introduction to Python, Lecture4
Anton Kasyanov, Introduction to Python, Lecture4
Anton Kasyanov
 
set.pptx
set.pptxset.pptx
set.pptx
satyabratPanda2
 
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
 
Python data type
Python data typePython data type
Python data type
Jaya Kumari
 
11 Introduction to lists.pptx
11 Introduction to lists.pptx11 Introduction to lists.pptx
11 Introduction to lists.pptx
ssuser8e50d8
 
Presentation on python data type
Presentation on python data typePresentation on python data type
Presentation on python data type
swati kushwaha
 
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
 
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
 
pythondatatypes.pptx
pythondatatypes.pptxpythondatatypes.pptx
pythondatatypes.pptx
ArchanaAravind1
 
PYTHON LISTsjnjsnljnsjnosojnosojnsojnsjsn.pptx
PYTHON LISTsjnjsnljnsjnosojnosojnsojnsjsn.pptxPYTHON LISTsjnjsnljnsjnosojnosojnsojnsjsn.pptx
PYTHON LISTsjnjsnljnsjnosojnosojnsojnsjsn.pptx
surajnath20
 
Python for beginners
Python for beginnersPython for beginners
Python for beginners
Ali Huseyn Aliyev
 
unit 1.docx
unit 1.docxunit 1.docx
unit 1.docx
ssuser2e84e4
 
AI_2nd Lab.pptx
AI_2nd Lab.pptxAI_2nd Lab.pptx
AI_2nd Lab.pptx
MohammedAlYemeni1
 
Lists and its functions in python for beginners
Lists and its functions in python for beginnersLists and its functions in python for beginners
Lists and its functions in python for beginners
Mohammad Usman
 
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
 
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
 
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
 
Python data type
Python data typePython data type
Python data type
nuripatidar
 
datatypes and its types.pptxgfmnghmghmfgm
datatypes and its types.pptxgfmnghmghmfgmdatatypes and its types.pptxgfmnghmghmfgm
datatypes and its types.pptxgfmnghmghmfgm
dibyashakti10
 
Anton Kasyanov, Introduction to Python, Lecture4
Anton Kasyanov, Introduction to Python, Lecture4Anton Kasyanov, Introduction to Python, Lecture4
Anton Kasyanov, Introduction to Python, Lecture4
Anton Kasyanov
 
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
 
Python data type
Python data typePython data type
Python data type
Jaya Kumari
 
11 Introduction to lists.pptx
11 Introduction to lists.pptx11 Introduction to lists.pptx
11 Introduction to lists.pptx
ssuser8e50d8
 
Presentation on python data type
Presentation on python data typePresentation on python data type
Presentation on python data type
swati kushwaha
 
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
 
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
 
PYTHON LISTsjnjsnljnsjnosojnosojnsojnsjsn.pptx
PYTHON LISTsjnjsnljnsjnosojnosojnsojnsjsn.pptxPYTHON LISTsjnjsnljnsjnosojnosojnsojnsjsn.pptx
PYTHON LISTsjnjsnljnsjnosojnosojnsojnsjsn.pptx
surajnath20
 
Lists and its functions in python for beginners
Lists and its functions in python for beginnersLists and its functions in python for beginners
Lists and its functions in python for beginners
Mohammad Usman
 
Ad

Recently uploaded (20)

Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
TechSoup
 
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.
 
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
 
How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18
Celine George
 
Kenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 CohortKenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 Cohort
EducationNC
 
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
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
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
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
Dr. Nasir Mustafa
 
Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
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
 
Lecture 4 INSECT CUTICLE and moulting.pptx
Lecture 4 INSECT CUTICLE and moulting.pptxLecture 4 INSECT CUTICLE and moulting.pptx
Lecture 4 INSECT CUTICLE and moulting.pptx
Arshad Shaikh
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
Herbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptxHerbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptx
RAJU THENGE
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
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
 
How to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 SalesHow to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 Sales
Celine George
 
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
TechSoup
 
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
 
How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18
Celine George
 
Kenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 CohortKenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 Cohort
EducationNC
 
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
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
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
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
Dr. Nasir Mustafa
 
Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
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
 
Lecture 4 INSECT CUTICLE and moulting.pptx
Lecture 4 INSECT CUTICLE and moulting.pptxLecture 4 INSECT CUTICLE and moulting.pptx
Lecture 4 INSECT CUTICLE and moulting.pptx
Arshad Shaikh
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
Herbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptxHerbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptx
RAJU THENGE
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
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
 
How to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 SalesHow to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 Sales
Celine George
 
Ad

Data types in python lecture (2)

  • 2. Contents: 1.What is the data type? 2.The data types in python. 3. MutableVs. Immutable objects?
  • 3. Data type it is just determine the type of the object in your program. Python will store that object with it’s type in the memory, also the interpreter needs to check the status of that object for the operation later. The general from to define any variable of any data type in python is look like below: Variable Name = Object A = 20 So, here A is the variable name and 20 is the object content which is assigned to the variable, you see now how python deal with the data types. 1.What is the data type?
  • 4. 2.The data types in python The data types in python can be classified into five categories or classes: 2.1 Boolean. 2.2 Numeric types. 2.3 Sequences. 2.4 Sets. 2.5 Mapping.
  • 5. 2.The data types in python 2.1 Boolean: This type has a two values either: True or False. This type can be used with decision making statements or where we want to represent the two values. Ex: T =True 2.2 Numeric types: This category can be classified into four data types: int, float, long and complex. Ex: A = 20 ; F = 2.5 ; L = 21321L ; C = 10 + 5j ► For long type now is not working in python 3.x but it was working in python 2.x and we need to put L in the last. For complex type is just consist of a two parts: Real part and imaginary part
  • 6. 2.3 Sequences: This category can be classified into four data types: String, bytes, byte array, list and tuple. Ex: S = “Ali Sattar” or S = str(“Hello”)  S is a string type B1 = b1’A’  b1 is a bytes type, it is like char type in other languages. B2 = b2’Python’  b2 is another bytes type, but it followed by sequence of letters. BA = (“Python, Java”, “utf8”)  b is of type bytearray returns a two items only. L = [‘String’, 24, 2.5, ‘b’]  L is of type list contains multiple items. T = (‘One’, ‘Two’, ‘Three’)  T is of type tuple, it is similar to list but there is a difference. 2. The data types in python
  • 7. 2.The data type in python ► For bytes data type is look like the char data type but here is expanded with not only one byte but with a sequence of bytes like you did noticed before in the examples. ► For list it is just a sequences of items started by 0m where list object can contains many data types for other objects ok. “List is changeable; means can be modified by insert, update and even delete”. ► For tuple is similar to list but surround it’s items with () instead of []. “Tuple is not changeable, so you cannot do update, insert and even delete”. ► You can use the method str() to convert any other data type to string type. ► We can use bytearray too if we want to represent a sequence of letters as list.
  • 8. 2.4 Sets: A set is unordered collection of items inside curly braces {}. The object inside the list is non-changeable but the set can be modified by adding or removing an items. The set can contain items of different data types, each item inside the set is separated comma (,) and built in using the method set(). The difference between set and list is list items can be updated in place while set items are not. Ex: my_Set = { 100, b’B’, “Ali Sattar”, 20.5, (1, 2, 3) } ► Here as you can see, we created a set of different items and with a different data types. 2. The data type in python
  • 9. 2.The data type in python 2.5 Mapping: Dictionary is the only data type here, the dictionary is unordered collection of items (elements) where the items are surrounded by a curly braces too {} like set. Each item is separated by comma and it has a key: value pair. Dictionary items are changeable like list and bytearray. Ex: Diction1 = { 1: ‘Sunday’, 2: ‘Monday’, 3: ‘Tuesday’ } Diction2 = { ‘A’: ‘Apple’, ‘B’: ‘Bannana’, ‘C’: ‘Chocolate’ } Diction3 = { 12: ‘3*4’, 15: ‘3*5’}
  • 10. 3. Mutable vs. Immutable objects Mutable Object: It is the object in which it’s value can be changed. For example: list, bytearray, byte and dictionary. Immutable Object: It is the object in which it’s value cannot be changed. For example: int, float, str, tuple and set.
  翻译: