SlideShare a Scribd company logo
Introduction to Python
Programming Unit 2
Contents:
⚫ Lists: List values, Accessing elements, List length, List
membership, List operations, List slices, Lists are mutable, List
deletion, Objects and references, Aliasing, Cloning lists, Lists and
for loops, List parameters, List methods, Pure functions and
modifiers, Functions that produce lists, Strings and lists, list and
range, Nested lists, Matrices.
⚫ Tuples are used for grouping data, Tuple assignment, Tuples as
return values, Composability of Data Structures.
⚫ Dictionaries: Dictionary operations, dictionary methods, aliasing
and copying.
LIST
⚫A list is an ordered set of values, where each
value is identified by an index
⚫The values that make up a list are called its
elements.
⚫Also called as sequences
LIST VALUES
⚫Ways to create a new list
⚫enclose the elements in square brackets [ ]:
Eg1 [10, 20, 30, 40]
Eg2 ["spam", "bungee", "swallow"]
Eg3 ["hello", 2.7, 5]
LIST VALUES
⚫ Lists that contain consecutive integers:
⚫ Empty list it is denoted [].
ACCESSING ELEMENTS
ACCESSING ELEMENTS
If you try to read or write an
element that does not exist, you
get a runtime error:
ACCESSING ELEMENTS
⚫If an index has a negative value, it counts
backward from the end of the list:
Using Loops
LIST LENGTH
⚫The function len returns the length of a list
LIST within another LIST
⚫The function len returns the length of a list
List membership
⚫in is a boolean operator that tests membership in
a sequence.
List operations
⚫The + operator concatenates lists
List operations
⚫Similarly, the * operator repeats a list a given
number of times
List slices
Lists are mutable
⚫lists are mutable, which means we can
change their elements.
List deletion
Objects and values
Objects and values
Aliasing
Cloning lists
If we want to modify a list and also keep a
copy of the original
Cloning lists
If we want to modify a list and also keep a
copy of the original
List parameters
Nested lists
Matrices
Nested lists are often used to
represent matrices
Strings and lists
Strings and lists- delimiter
Strings and lists- join
List Methods
List Methods
1. append()
syntax
list.append (element)
['Mathematics', 'chemistry', 1997, 2000, 20544]
List Methods
insert()
syntax
list.insert(position, element)
['Mathematics', 'chemistry', 10087,
1997, 2000]
List Methods
sum()
syntax
sum(List)
List Methods
Length()
syntax
len(list_name)
10
List Methods
reverse()
1
List Methods
Sort( )
Tuples
Tuple
⚫A tuple that is similar to a list except that it is
immutable.
⚫Syntactically, a tuple is a comma-separated list
of values:
Tuple
⚫To create a tuple with a single element, we
have to include the final comma:
>>> t1 = (’a’,)
• Without the comma, Python treats (’a’) as a
string in parentheses:
Tuple
If we try to modify one of the elements of
the tuple, we get an error:
Tuple packing and unpacking
Tuple packing is nothing but the creation of
tuple, whereas tuple unpacking means to extract
tuple values and store them in individual
variables.
Tuple assignment
Tuple assignment
Tuples as return values
⚫Functions can return tuples as return values
Composability of Data Structures
⚫Tuples items can themselves be other tuples.
Dictionary
Dictionaries
⚫In a dictionary, the indices are called keys,
so the elements are called key-value pairs.
⚫One way to create a dictionary is to start
with the empty dictionary and add elements.
⚫The empty dictionary is denoted {}
Dictionaries
Dictionaries
Another way to create a
dictionary
print(len(Subjects)
)
Dictionary operations
1. The del statement removes a key-
value pair from a dictionary
2.
print(len(Subjects))
Dictionary methods
▪ A method is similar to a function, it
takes arguments and returns a value
but the syntax is different.
▪ print(Subjects.keys())
dict_keys([2, 3, 4])
Dictionary methods
▪ The items method returns both, in the
form of a list of tuples—one for each
key-value pair:
print(Subjects.items())
dict_items([(2, 'Physics'), (3,
'Electronics'), (4, 'Python')])
Dictionary methods
▪ the method has key takes a key and
returns true (1) if the key appears in
the dictionary:
Aliasing and copying
▪ Whenever two variables refer to the same object,
changes to one affect the other.
▪ If you want to modify a dictionary and keep a
copy of the original, use the copy method.
▪ ISEM and Subjects refer to the same object
▪ Copied creates a new copy of Subjects

More Related Content

Similar to Python-Ukllllllllllllllllllllllllllllnit 2.pdklllllllf

Ap Power Point Chpt6
Ap Power Point Chpt6Ap Power Point Chpt6
Ap Power Point Chpt6
dplunkett
 
tupple.pptx
tupple.pptxtupple.pptx
tupple.pptx
satyabratPanda2
 
List , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in pythonList , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in python
channa basava
 
Basic data structures in python
Basic data structures in pythonBasic data structures in python
Basic data structures in python
Celine George
 
dataStructuresInPython.pptx
dataStructuresInPython.pptxdataStructuresInPython.pptx
dataStructuresInPython.pptx
YashaswiniChandrappa1
 
Data structures in Python
Data structures in PythonData structures in Python
Data structures in Python
MITULJAMANG
 
Chapter 15 Lists
Chapter 15 ListsChapter 15 Lists
Chapter 15 Lists
Praveen M Jigajinni
 
Introduction of Python-1.pdf
Introduction of Python-1.pdfIntroduction of Python-1.pdf
Introduction of Python-1.pdf
SyamsulFattanSSos
 
Python Collections
Python CollectionsPython Collections
Python Collections
sachingarg0
 
Python for Beginners(v3)
Python for Beginners(v3)Python for Beginners(v3)
Python for Beginners(v3)
Panimalar Engineering College
 
Built-in Data Structures in python 3.pdf
Built-in Data Structures in python 3.pdfBuilt-in Data Structures in python 3.pdf
Built-in Data Structures in python 3.pdf
alivaisi1
 
Python_23B81A6625presentationlistvsdict.pptx
Python_23B81A6625presentationlistvsdict.pptxPython_23B81A6625presentationlistvsdict.pptx
Python_23B81A6625presentationlistvsdict.pptx
PradeepSarampalli
 
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
 
UNIT 1 - Revision of Basics - II.pptx
UNIT 1 - Revision of Basics - II.pptxUNIT 1 - Revision of Basics - II.pptx
UNIT 1 - Revision of Basics - II.pptx
NishanSidhu2
 
Data Structures in Python
Data Structures in PythonData Structures in Python
Data Structures in Python
Devashish Kumar
 
FINAL revised LIST in Python.pdf
FINAL revised LIST in Python.pdfFINAL revised LIST in Python.pdf
FINAL revised LIST in Python.pdf
SanjayChoudhary270270
 
Python list manipulation basics in detail.pdf
Python list  manipulation basics in detail.pdfPython list  manipulation basics in detail.pdf
Python list manipulation basics in detail.pdf
neonaveen
 
Array.ppt
Array.pptArray.ppt
Array.ppt
SbsOmit1
 
array.ppt
array.pptarray.ppt
array.ppt
rajput0302
 
lists_list_of_liststuples_of_python.pptx
lists_list_of_liststuples_of_python.pptxlists_list_of_liststuples_of_python.pptx
lists_list_of_liststuples_of_python.pptx
ShanthiJeyabal
 

Similar to Python-Ukllllllllllllllllllllllllllllnit 2.pdklllllllf (20)

Ap Power Point Chpt6
Ap Power Point Chpt6Ap Power Point Chpt6
Ap Power Point Chpt6
 
tupple.pptx
tupple.pptxtupple.pptx
tupple.pptx
 
List , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in pythonList , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in python
 
Basic data structures in python
Basic data structures in pythonBasic data structures in python
Basic data structures in python
 
dataStructuresInPython.pptx
dataStructuresInPython.pptxdataStructuresInPython.pptx
dataStructuresInPython.pptx
 
Data structures in Python
Data structures in PythonData structures in Python
Data structures in Python
 
Chapter 15 Lists
Chapter 15 ListsChapter 15 Lists
Chapter 15 Lists
 
Introduction of Python-1.pdf
Introduction of Python-1.pdfIntroduction of Python-1.pdf
Introduction of Python-1.pdf
 
Python Collections
Python CollectionsPython Collections
Python Collections
 
Python for Beginners(v3)
Python for Beginners(v3)Python for Beginners(v3)
Python for Beginners(v3)
 
Built-in Data Structures in python 3.pdf
Built-in Data Structures in python 3.pdfBuilt-in Data Structures in python 3.pdf
Built-in Data Structures in python 3.pdf
 
Python_23B81A6625presentationlistvsdict.pptx
Python_23B81A6625presentationlistvsdict.pptxPython_23B81A6625presentationlistvsdict.pptx
Python_23B81A6625presentationlistvsdict.pptx
 
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
 
UNIT 1 - Revision of Basics - II.pptx
UNIT 1 - Revision of Basics - II.pptxUNIT 1 - Revision of Basics - II.pptx
UNIT 1 - Revision of Basics - II.pptx
 
Data Structures in Python
Data Structures in PythonData Structures in Python
Data Structures in Python
 
FINAL revised LIST in Python.pdf
FINAL revised LIST in Python.pdfFINAL revised LIST in Python.pdf
FINAL revised LIST in Python.pdf
 
Python list manipulation basics in detail.pdf
Python list  manipulation basics in detail.pdfPython list  manipulation basics in detail.pdf
Python list manipulation basics in detail.pdf
 
Array.ppt
Array.pptArray.ppt
Array.ppt
 
array.ppt
array.pptarray.ppt
array.ppt
 
lists_list_of_liststuples_of_python.pptx
lists_list_of_liststuples_of_python.pptxlists_list_of_liststuples_of_python.pptx
lists_list_of_liststuples_of_python.pptx
 

Recently uploaded

Top 10 Best Ayurvedic Kidney Stone Syrups in India
Top 10 Best Ayurvedic Kidney Stone Syrups in IndiaTop 10 Best Ayurvedic Kidney Stone Syrups in India
Top 10 Best Ayurvedic Kidney Stone Syrups in India
Swastik Ayurveda
 
Journal Article Review on Rasamanikya
Journal Article Review on RasamanikyaJournal Article Review on Rasamanikya
Journal Article Review on Rasamanikya
Dr. Jyothirmai Paindla
 
Top Effective Soaps for Fungal Skin Infections in India
Top Effective Soaps for Fungal Skin Infections in IndiaTop Effective Soaps for Fungal Skin Infections in India
Top Effective Soaps for Fungal Skin Infections in India
SwisschemDerma
 
CHEMOTHERAPY_RDP_CHAPTER 1_ANTI TB DRUGS.pdf
CHEMOTHERAPY_RDP_CHAPTER 1_ANTI TB DRUGS.pdfCHEMOTHERAPY_RDP_CHAPTER 1_ANTI TB DRUGS.pdf
CHEMOTHERAPY_RDP_CHAPTER 1_ANTI TB DRUGS.pdf
rishi2789
 
Thyroid Gland- Gross Anatomy by Dr. Rabia Inam Gandapore.pptx
Thyroid Gland- Gross Anatomy by Dr. Rabia Inam Gandapore.pptxThyroid Gland- Gross Anatomy by Dr. Rabia Inam Gandapore.pptx
Thyroid Gland- Gross Anatomy by Dr. Rabia Inam Gandapore.pptx
Dr. Rabia Inam Gandapore
 
ABDOMINAL TRAUMA in pediatrics part one.
ABDOMINAL TRAUMA in pediatrics part one.ABDOMINAL TRAUMA in pediatrics part one.
ABDOMINAL TRAUMA in pediatrics part one.
drhasanrajab
 
#cALL# #gIRLS# In Dehradun ꧁❤8107221448❤꧂#cALL# #gIRLS# Service In Dehradun W...
#cALL# #gIRLS# In Dehradun ꧁❤8107221448❤꧂#cALL# #gIRLS# Service In Dehradun W...#cALL# #gIRLS# In Dehradun ꧁❤8107221448❤꧂#cALL# #gIRLS# Service In Dehradun W...
#cALL# #gIRLS# In Dehradun ꧁❤8107221448❤꧂#cALL# #gIRLS# Service In Dehradun W...
chandankumarsmartiso
 
Best Ayurvedic medicine for Gas and Indigestion
Best Ayurvedic medicine for Gas and IndigestionBest Ayurvedic medicine for Gas and Indigestion
Best Ayurvedic medicine for Gas and Indigestion
Swastik Ayurveda
 
Hemodialysis: Chapter 4, Dialysate Circuit - Dr.Gawad
Hemodialysis: Chapter 4, Dialysate Circuit - Dr.GawadHemodialysis: Chapter 4, Dialysate Circuit - Dr.Gawad
Hemodialysis: Chapter 4, Dialysate Circuit - Dr.Gawad
NephroTube - Dr.Gawad
 
THERAPEUTIC ANTISENSE MOLECULES .pptx
THERAPEUTIC ANTISENSE MOLECULES    .pptxTHERAPEUTIC ANTISENSE MOLECULES    .pptx
THERAPEUTIC ANTISENSE MOLECULES .pptx
70KRISHPATEL
 
Aortic Association CBL Pilot April 19 – 20 Bern
Aortic Association CBL Pilot April 19 – 20 BernAortic Association CBL Pilot April 19 – 20 Bern
Aortic Association CBL Pilot April 19 – 20 Bern
suvadeepdas911
 
Novas diretrizes da OMS para os cuidados perinatais de mais qualidade
Novas diretrizes da OMS para os cuidados perinatais de mais qualidadeNovas diretrizes da OMS para os cuidados perinatais de mais qualidade
Novas diretrizes da OMS para os cuidados perinatais de mais qualidade
Prof. Marcus Renato de Carvalho
 
NVBDCP.pptx Nation vector borne disease control program
NVBDCP.pptx Nation vector borne disease control programNVBDCP.pptx Nation vector borne disease control program
NVBDCP.pptx Nation vector borne disease control program
Sapna Thakur
 
Role of Mukta Pishti in the Management of Hyperthyroidism
Role of Mukta Pishti in the Management of HyperthyroidismRole of Mukta Pishti in the Management of Hyperthyroidism
Role of Mukta Pishti in the Management of Hyperthyroidism
Dr. Jyothirmai Paindla
 
Muscles of Mastication by Dr. Rabia Inam Gandapore.pptx
Muscles of Mastication by Dr. Rabia Inam Gandapore.pptxMuscles of Mastication by Dr. Rabia Inam Gandapore.pptx
Muscles of Mastication by Dr. Rabia Inam Gandapore.pptx
Dr. Rabia Inam Gandapore
 
Top-Vitamin-Supplement-Brands-in-India List
Top-Vitamin-Supplement-Brands-in-India ListTop-Vitamin-Supplement-Brands-in-India List
Top-Vitamin-Supplement-Brands-in-India List
SwisschemDerma
 
The Electrocardiogram - Physiologic Principles
The Electrocardiogram - Physiologic PrinciplesThe Electrocardiogram - Physiologic Principles
The Electrocardiogram - Physiologic Principles
MedicoseAcademics
 
Does Over-Masturbation Contribute to Chronic Prostatitis.pptx
Does Over-Masturbation Contribute to Chronic Prostatitis.pptxDoes Over-Masturbation Contribute to Chronic Prostatitis.pptx
Does Over-Masturbation Contribute to Chronic Prostatitis.pptx
walterHu5
 
Integrating Ayurveda into Parkinson’s Management: A Holistic Approach
Integrating Ayurveda into Parkinson’s Management: A Holistic ApproachIntegrating Ayurveda into Parkinson’s Management: A Holistic Approach
Integrating Ayurveda into Parkinson’s Management: A Holistic Approach
Ayurveda ForAll
 
Osteoporosis - Definition , Evaluation and Management .pdf
Osteoporosis - Definition , Evaluation and Management .pdfOsteoporosis - Definition , Evaluation and Management .pdf
Osteoporosis - Definition , Evaluation and Management .pdf
Jim Jacob Roy
 

Recently uploaded (20)

Top 10 Best Ayurvedic Kidney Stone Syrups in India
Top 10 Best Ayurvedic Kidney Stone Syrups in IndiaTop 10 Best Ayurvedic Kidney Stone Syrups in India
Top 10 Best Ayurvedic Kidney Stone Syrups in India
 
Journal Article Review on Rasamanikya
Journal Article Review on RasamanikyaJournal Article Review on Rasamanikya
Journal Article Review on Rasamanikya
 
Top Effective Soaps for Fungal Skin Infections in India
Top Effective Soaps for Fungal Skin Infections in IndiaTop Effective Soaps for Fungal Skin Infections in India
Top Effective Soaps for Fungal Skin Infections in India
 
CHEMOTHERAPY_RDP_CHAPTER 1_ANTI TB DRUGS.pdf
CHEMOTHERAPY_RDP_CHAPTER 1_ANTI TB DRUGS.pdfCHEMOTHERAPY_RDP_CHAPTER 1_ANTI TB DRUGS.pdf
CHEMOTHERAPY_RDP_CHAPTER 1_ANTI TB DRUGS.pdf
 
Thyroid Gland- Gross Anatomy by Dr. Rabia Inam Gandapore.pptx
Thyroid Gland- Gross Anatomy by Dr. Rabia Inam Gandapore.pptxThyroid Gland- Gross Anatomy by Dr. Rabia Inam Gandapore.pptx
Thyroid Gland- Gross Anatomy by Dr. Rabia Inam Gandapore.pptx
 
ABDOMINAL TRAUMA in pediatrics part one.
ABDOMINAL TRAUMA in pediatrics part one.ABDOMINAL TRAUMA in pediatrics part one.
ABDOMINAL TRAUMA in pediatrics part one.
 
#cALL# #gIRLS# In Dehradun ꧁❤8107221448❤꧂#cALL# #gIRLS# Service In Dehradun W...
#cALL# #gIRLS# In Dehradun ꧁❤8107221448❤꧂#cALL# #gIRLS# Service In Dehradun W...#cALL# #gIRLS# In Dehradun ꧁❤8107221448❤꧂#cALL# #gIRLS# Service In Dehradun W...
#cALL# #gIRLS# In Dehradun ꧁❤8107221448❤꧂#cALL# #gIRLS# Service In Dehradun W...
 
Best Ayurvedic medicine for Gas and Indigestion
Best Ayurvedic medicine for Gas and IndigestionBest Ayurvedic medicine for Gas and Indigestion
Best Ayurvedic medicine for Gas and Indigestion
 
Hemodialysis: Chapter 4, Dialysate Circuit - Dr.Gawad
Hemodialysis: Chapter 4, Dialysate Circuit - Dr.GawadHemodialysis: Chapter 4, Dialysate Circuit - Dr.Gawad
Hemodialysis: Chapter 4, Dialysate Circuit - Dr.Gawad
 
THERAPEUTIC ANTISENSE MOLECULES .pptx
THERAPEUTIC ANTISENSE MOLECULES    .pptxTHERAPEUTIC ANTISENSE MOLECULES    .pptx
THERAPEUTIC ANTISENSE MOLECULES .pptx
 
Aortic Association CBL Pilot April 19 – 20 Bern
Aortic Association CBL Pilot April 19 – 20 BernAortic Association CBL Pilot April 19 – 20 Bern
Aortic Association CBL Pilot April 19 – 20 Bern
 
Novas diretrizes da OMS para os cuidados perinatais de mais qualidade
Novas diretrizes da OMS para os cuidados perinatais de mais qualidadeNovas diretrizes da OMS para os cuidados perinatais de mais qualidade
Novas diretrizes da OMS para os cuidados perinatais de mais qualidade
 
NVBDCP.pptx Nation vector borne disease control program
NVBDCP.pptx Nation vector borne disease control programNVBDCP.pptx Nation vector borne disease control program
NVBDCP.pptx Nation vector borne disease control program
 
Role of Mukta Pishti in the Management of Hyperthyroidism
Role of Mukta Pishti in the Management of HyperthyroidismRole of Mukta Pishti in the Management of Hyperthyroidism
Role of Mukta Pishti in the Management of Hyperthyroidism
 
Muscles of Mastication by Dr. Rabia Inam Gandapore.pptx
Muscles of Mastication by Dr. Rabia Inam Gandapore.pptxMuscles of Mastication by Dr. Rabia Inam Gandapore.pptx
Muscles of Mastication by Dr. Rabia Inam Gandapore.pptx
 
Top-Vitamin-Supplement-Brands-in-India List
Top-Vitamin-Supplement-Brands-in-India ListTop-Vitamin-Supplement-Brands-in-India List
Top-Vitamin-Supplement-Brands-in-India List
 
The Electrocardiogram - Physiologic Principles
The Electrocardiogram - Physiologic PrinciplesThe Electrocardiogram - Physiologic Principles
The Electrocardiogram - Physiologic Principles
 
Does Over-Masturbation Contribute to Chronic Prostatitis.pptx
Does Over-Masturbation Contribute to Chronic Prostatitis.pptxDoes Over-Masturbation Contribute to Chronic Prostatitis.pptx
Does Over-Masturbation Contribute to Chronic Prostatitis.pptx
 
Integrating Ayurveda into Parkinson’s Management: A Holistic Approach
Integrating Ayurveda into Parkinson’s Management: A Holistic ApproachIntegrating Ayurveda into Parkinson’s Management: A Holistic Approach
Integrating Ayurveda into Parkinson’s Management: A Holistic Approach
 
Osteoporosis - Definition , Evaluation and Management .pdf
Osteoporosis - Definition , Evaluation and Management .pdfOsteoporosis - Definition , Evaluation and Management .pdf
Osteoporosis - Definition , Evaluation and Management .pdf
 

Python-Ukllllllllllllllllllllllllllllnit 2.pdklllllllf