SlideShare a Scribd company logo
Python
a programming language
Class 3
Collection data types in the Python
 List
 Tuple
 Set
 Dictionary
List
 List is a collection which is ordered and changeable. Allows duplicate members.
 Syntax:
List_name=[ item1, item2,……]
print(List_name)
 Eg:
thislist = ["apple", "banana", "cherry"]
print(thislist)
Operations on List
 Accessing items
 Changing Elements
Access Items
Syntax:
List_name[ index_number ]
Eg:
thislist = ["apple", "banana", "cherry"]
print(thislist[1])
Change Item Value
 Syntax:
List_name [ Index_number ] = value
 Eg:
thislist = ["apple", "banana", "cherry"]
thislist[1] = "blackcurrant"
print(thislist)
Loop through a list
Syntax:
for variable_name in List_name:
statements
 Eg:
thislist = ["apple", "banana", "cherry"]
for x in thislist:
print(x)
Check if Item exist
Syntax:
if item in List_name:
statements
 Eg:
thislist = ["apple", "banana", "cherry"]
if "apple" in thislist:
print("Yes, 'apple' is in the fruits list")
List Length
Syntax:
len(List_name)
 Eg
thislist = ["apple", "banana", "cherry"]
print(len(thislist))
Add Items
Syntax:
List_name.append(“item”)
 Eg
thislist = ["apple", "banana", "cherry"]
thislist.append("orange")
print(thislist)
Insert()
 To add an item at the specified index, use the insert() method:
Syntax:
List_name.insert( index,value)
 Eg:
thislist = ["apple", "banana", "cherry"]
thislist.insert(1, "orange")
print(thislist)
Remove Item
Syntax:
List_name.remove(element)
 Eg:
thislist = ["apple", "banana", "cherry"]
thislist.remove("banana")
print(thislist)
Pop()
 The pop() method removes the specified index,(or the last item if index is not
specified)
Syntax:
List_name.pop()
 Eg:
thislist = ["apple", "banana", "cherry"]
thislist.pop()
print(thislist)
Del()
 The del keyword removes the specified index:
Syntax:
del List_name[ index ]
 EG:
thislist = ["apple", "banana", "cherry"]
del thislist[0]
print(thislist)
Clear()
 The clear() empties the list
Syntax:
List_name.clear()
 Eg:
thislist = ["apple", "banana", "cherry"]
thislist.clear()
print(thislist)
List methods
Method Description
append() Adds an element at the end of the list
clear() Removes all the elements from the list
copy() Returns a copy of the list
count() Returns the number of elements with the specified value
extend() Add the elements of a list (or any iterable), to the end of the current list
index() Returns the index of the first element with the specified value
insert() Adds an element at the specified position
pop() Removes the element at the specified position
remove() Removes the item with the specified value
reverse() Reverses the order of the list
sort() Sorts the list
Exercise:
 Print the 2nd item in a list
 Replace the 1st element with “kiwi”
 Append “mango” to the current list
 What is insert()
 What is remove()

More Related Content

What's hot (20)

PDF
Road to Power Query NINJA – 1st STEP
Takeshi Kagata
 
PPT
Php array
Core Lee
 
PPTX
LIST IN PYTHON
vikram mahendra
 
PPTX
Python list
ArchanaBhumkar
 
PDF
Php array
Nikul Shah
 
PPT
Arrays in PHP
Compare Infobase Limited
 
PDF
Python Workshop Part 2. LUG Maniapl
Ankur Shrivastava
 
PDF
Python programming : List and tuples
Emertxe Information Technologies Pvt Ltd
 
PPT
Php Using Arrays
mussawir20
 
PPTX
List in Python
Siddique Ibrahim
 
PDF
Arrays in PHP
Vineet Kumar Saini
 
PPTX
Array,lists and hashes in perl
sana mateen
 
PDF
Python Variable Types, List, Tuple, Dictionary
Soba Arjun
 
PPTX
Pa1 lists subset
aiclub_slides
 
PDF
Swift tips and tricks
HomeroJuniorOliveira1
 
PDF
List , tuples, dictionaries and regular expressions in python
channa basava
 
PDF
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
PROIDEA
 
PPTX
Array in php
ilakkiya
 
ODT
Sql Tags
Sutharsan nagarajan
 
PPTX
Marcs (bio)perl course
BITS
 
Road to Power Query NINJA – 1st STEP
Takeshi Kagata
 
Php array
Core Lee
 
LIST IN PYTHON
vikram mahendra
 
Python list
ArchanaBhumkar
 
Php array
Nikul Shah
 
Python Workshop Part 2. LUG Maniapl
Ankur Shrivastava
 
Python programming : List and tuples
Emertxe Information Technologies Pvt Ltd
 
Php Using Arrays
mussawir20
 
List in Python
Siddique Ibrahim
 
Arrays in PHP
Vineet Kumar Saini
 
Array,lists and hashes in perl
sana mateen
 
Python Variable Types, List, Tuple, Dictionary
Soba Arjun
 
Pa1 lists subset
aiclub_slides
 
Swift tips and tricks
HomeroJuniorOliveira1
 
List , tuples, dictionaries and regular expressions in python
channa basava
 
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
PROIDEA
 
Array in php
ilakkiya
 
Marcs (bio)perl course
BITS
 

Similar to Python Collection datatypes (20)

PPTX
list and control statement.pptx
ssuser8f0410
 
PPTX
Python Lists is a a evry jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...
KavineshKumarS
 
PPTX
Python Lists.pptx
adityakumawat625
 
PPTX
Python Array Power Point Presentation.pptx
MeowTwo2
 
PPTX
Python for the data science most in cse.pptx
Rajasekhar364622
 
PPTX
PYTHON-PROGRAMMING-UNIT-III.pptx kghbg kfhjf jruufg jtuuf
DeepakRattan3
 
PPTX
list in python and traversal of list.pptx
urvashipundir04
 
PPTX
powerpoint 2-13.pptx
JuanPicasso7
 
PPTX
Python - List, Dictionaries, Tuples,Sets
Mohan Arumugam
 
DOCX
List Data Structure.docx
manohar25689
 
PPTX
Lists Data Structures and Algorithm.pptx
CollegeDataComptroll
 
PPT
UNIT 4 PY.ppt - DATA STRUCTURE IN PYTHON
drkangurajuphd
 
PPTX
Programming with Python_Unit-3-Notes.pptx
YugandharaNalavade
 
PDF
Python List
Soba Arjun
 
PDF
python_avw - Unit-03.pdf
AshaWankar1
 
PPTX
LIST IN PYTHON-PART 3[BUILT IN PYTHON]
vikram mahendra
 
PDF
Unit 1-Part-4-Lists, tuples and dictionaries.pdf
Harsha Patil
 
PDF
Data type list_methods_in_python
deepalishinkar1
 
list and control statement.pptx
ssuser8f0410
 
Python Lists is a a evry jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...
KavineshKumarS
 
Python Lists.pptx
adityakumawat625
 
Python Array Power Point Presentation.pptx
MeowTwo2
 
Python for the data science most in cse.pptx
Rajasekhar364622
 
PYTHON-PROGRAMMING-UNIT-III.pptx kghbg kfhjf jruufg jtuuf
DeepakRattan3
 
list in python and traversal of list.pptx
urvashipundir04
 
powerpoint 2-13.pptx
JuanPicasso7
 
Python - List, Dictionaries, Tuples,Sets
Mohan Arumugam
 
List Data Structure.docx
manohar25689
 
Lists Data Structures and Algorithm.pptx
CollegeDataComptroll
 
UNIT 4 PY.ppt - DATA STRUCTURE IN PYTHON
drkangurajuphd
 
Programming with Python_Unit-3-Notes.pptx
YugandharaNalavade
 
Python List
Soba Arjun
 
python_avw - Unit-03.pdf
AshaWankar1
 
LIST IN PYTHON-PART 3[BUILT IN PYTHON]
vikram mahendra
 
Unit 1-Part-4-Lists, tuples and dictionaries.pdf
Harsha Patil
 
Data type list_methods_in_python
deepalishinkar1
 
Ad

Recently uploaded (20)

PPTX
NEUROMOROPHIC nu iajwojeieheueueueu.pptx
knkoodalingam39
 
PDF
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
PPTX
ISO/IEC JTC 1/WG 9 (MAR) Convenor Report
Kurata Takeshi
 
PPTX
原版一样(Acadia毕业证书)加拿大阿卡迪亚大学毕业证办理方法
Taqyea
 
PDF
BioSensors glucose monitoring, cholestrol
nabeehasahar1
 
PPTX
site survey architecture student B.arch.
sri02032006
 
PDF
International Journal of Information Technology Convergence and services (IJI...
ijitcsjournal4
 
PDF
Water Design_Manual_2005. KENYA FOR WASTER SUPPLY AND SEWERAGE
DancanNgutuku
 
PDF
PRIZ Academy - Change Flow Thinking Master Change with Confidence.pdf
PRIZ Guru
 
PDF
Unified_Cloud_Comm_Presentation anil singh ppt
anilsingh298751
 
PDF
Ethics and Trustworthy AI in Healthcare – Governing Sensitive Data, Profiling...
AlqualsaDIResearchGr
 
DOCX
8th International Conference on Electrical Engineering (ELEN 2025)
elelijjournal653
 
PDF
monopile foundation seminar topic for civil engineering students
Ahina5
 
PDF
Book.pdf01_Intro.ppt algorithm for preperation stu used
archu26
 
PPTX
Introduction to Neural Networks and Perceptron Learning Algorithm.pptx
Kayalvizhi A
 
PPTX
Innowell Capability B0425 - Commercial Buildings.pptx
regobertroza
 
PPTX
Structural Functiona theory this important for the theorist
cagumaydanny26
 
PPTX
Presentation on Foundation Design for Civil Engineers.pptx
KamalKhan563106
 
PPTX
Thermal runway and thermal stability.pptx
godow93766
 
PPTX
MPMC_Module-2 xxxxxxxxxxxxxxxxxxxxx.pptx
ShivanshVaidya5
 
NEUROMOROPHIC nu iajwojeieheueueueu.pptx
knkoodalingam39
 
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
ISO/IEC JTC 1/WG 9 (MAR) Convenor Report
Kurata Takeshi
 
原版一样(Acadia毕业证书)加拿大阿卡迪亚大学毕业证办理方法
Taqyea
 
BioSensors glucose monitoring, cholestrol
nabeehasahar1
 
site survey architecture student B.arch.
sri02032006
 
International Journal of Information Technology Convergence and services (IJI...
ijitcsjournal4
 
Water Design_Manual_2005. KENYA FOR WASTER SUPPLY AND SEWERAGE
DancanNgutuku
 
PRIZ Academy - Change Flow Thinking Master Change with Confidence.pdf
PRIZ Guru
 
Unified_Cloud_Comm_Presentation anil singh ppt
anilsingh298751
 
Ethics and Trustworthy AI in Healthcare – Governing Sensitive Data, Profiling...
AlqualsaDIResearchGr
 
8th International Conference on Electrical Engineering (ELEN 2025)
elelijjournal653
 
monopile foundation seminar topic for civil engineering students
Ahina5
 
Book.pdf01_Intro.ppt algorithm for preperation stu used
archu26
 
Introduction to Neural Networks and Perceptron Learning Algorithm.pptx
Kayalvizhi A
 
Innowell Capability B0425 - Commercial Buildings.pptx
regobertroza
 
Structural Functiona theory this important for the theorist
cagumaydanny26
 
Presentation on Foundation Design for Civil Engineers.pptx
KamalKhan563106
 
Thermal runway and thermal stability.pptx
godow93766
 
MPMC_Module-2 xxxxxxxxxxxxxxxxxxxxx.pptx
ShivanshVaidya5
 
Ad

Python Collection datatypes

  • 2. Collection data types in the Python  List  Tuple  Set  Dictionary
  • 3. List  List is a collection which is ordered and changeable. Allows duplicate members.  Syntax: List_name=[ item1, item2,……] print(List_name)  Eg: thislist = ["apple", "banana", "cherry"] print(thislist)
  • 4. Operations on List  Accessing items  Changing Elements
  • 5. Access Items Syntax: List_name[ index_number ] Eg: thislist = ["apple", "banana", "cherry"] print(thislist[1])
  • 6. Change Item Value  Syntax: List_name [ Index_number ] = value  Eg: thislist = ["apple", "banana", "cherry"] thislist[1] = "blackcurrant" print(thislist)
  • 7. Loop through a list Syntax: for variable_name in List_name: statements  Eg: thislist = ["apple", "banana", "cherry"] for x in thislist: print(x)
  • 8. Check if Item exist Syntax: if item in List_name: statements  Eg: thislist = ["apple", "banana", "cherry"] if "apple" in thislist: print("Yes, 'apple' is in the fruits list")
  • 9. List Length Syntax: len(List_name)  Eg thislist = ["apple", "banana", "cherry"] print(len(thislist))
  • 10. Add Items Syntax: List_name.append(“item”)  Eg thislist = ["apple", "banana", "cherry"] thislist.append("orange") print(thislist)
  • 11. Insert()  To add an item at the specified index, use the insert() method: Syntax: List_name.insert( index,value)  Eg: thislist = ["apple", "banana", "cherry"] thislist.insert(1, "orange") print(thislist)
  • 12. Remove Item Syntax: List_name.remove(element)  Eg: thislist = ["apple", "banana", "cherry"] thislist.remove("banana") print(thislist)
  • 13. Pop()  The pop() method removes the specified index,(or the last item if index is not specified) Syntax: List_name.pop()  Eg: thislist = ["apple", "banana", "cherry"] thislist.pop() print(thislist)
  • 14. Del()  The del keyword removes the specified index: Syntax: del List_name[ index ]  EG: thislist = ["apple", "banana", "cherry"] del thislist[0] print(thislist)
  • 15. Clear()  The clear() empties the list Syntax: List_name.clear()  Eg: thislist = ["apple", "banana", "cherry"] thislist.clear() print(thislist)
  • 16. List methods Method Description append() Adds an element at the end of the list clear() Removes all the elements from the list copy() Returns a copy of the list count() Returns the number of elements with the specified value extend() Add the elements of a list (or any iterable), to the end of the current list index() Returns the index of the first element with the specified value insert() Adds an element at the specified position pop() Removes the element at the specified position remove() Removes the item with the specified value reverse() Reverses the order of the list sort() Sorts the list
  • 17. Exercise:  Print the 2nd item in a list  Replace the 1st element with “kiwi”  Append “mango” to the current list  What is insert()  What is remove()