SlideShare a Scribd company logo
1 of 17
By: Sachin Garg
CT University
There are four collection data types in the Python programming language:
o List is a collection which is ordered and changeable. Allows duplicate members.
o Tuple is a collection which is ordered and unchangeable. Allows duplicate
members.
o Dictionary is a collection which is unordered, changeable and indexed. No
duplicate members.
Python Collections (Arrays)
A list is created by placing all the items (elements) inside a square
bracket [ ], separated by commas.
It can have any number of items and they may be of different types
(integer, float, string etc.).
Example:
list = [1, 2, 3] # list with same data-types list = [1, "Hello", 3.4] #
list with mixed data-types
List Creation
 It can be access in several ways
 Use the index operator [] to access an item in a list. Index starts from 0.
So, a list having 5 elements will have index from 0 to 4.
 Example:
list = ['p','r','o','b','e']
Output
O
bprint(list[2]) #Positive Indexing b
print(list[-2]) #Negative Indexing
Access Items From List
 Accessing a range of items in a list by using the slicing operator [ ] using
(colon :).
 Slicing can be best visualized by considering the index to be between the
elements.
 Example:
list = ['p','r','o','b','e']
print(list[0:4]) #Positive
print(list[-2:-1]) # Negative
Output
['p', 'r', 'o', 'b']
['b']
4
Slice List
 append()
 count()
- Add an element to the end of the list.
- Returns the count of number of items passed as an argument.
- Add all elements of a list to the another list.
- Returns the index of the first matched item.
- Insert an item at the defined index.
- Removes and returns an element at the given index.
- Returns a shallow copy of the list
- Removes an item from the list.
- Reverse the order of items in the list.
 extend()
 index()
 insert()
 pop()
 copy()
 remove()
 reverse()
 sort() - Sort items in a list in ascending order.
5
List Methods
• It is a collection of object much like a list.
• The main different between tuple and list is that tuples are
immutable.
• It represent as ( ).
• Values of a tuple are syntactically separated by commas.
• Tuple elements cannot be changes.
Tuples
Tuple1 = ( ) //empty tuple
Tuple2 = ('zooming', 'For ’) //tuple with
strings l i s t 1 = [1, 2, 4, 5, 6]
Tuple
3
= tuple ( l i s t 1 ) //tuple with the use of l i s t
Tuple
4
= (‘zooming’,) * 3 //tuple with repetition
Tuple
5
= (5, 'Welcome', 7, ‘zooming’) //tuple with
mixed datatypes
Creation of Tuples
• Concatenation of tuple is the process of joining of two or more Tuples.
• Concatenation is done by theuse of ‘+’ operator.
• Concatenationof tuples is done always from the end of the original tuple.
• Other arithmetic operations do not apply on Tuples.
# Concatenaton of tuples Tuple1 = (0, 1, 2, 3)
Tuple2 = (‘Zooming', 'For', ‘stud')
Tuple3 = Tuple1 + Tuple2
print("nTuples after Concatenaton: " )
print(Tuple3)
Tuples aft er Concatenaton:
( 0 , 1, 2, 3, ‘Zooming', ' F o r ' , ‘ s t u d ' )
Concatenation of Tuples
# with Numbers
Tuple1 = tuple(‘ZOOMING')
# From First element
print(Tuple1[1:])
# Reversing the Tuple
print(Tuple1[::-1])
# Printing elements of a
Range
print(Tuple1[2:5])
( ‘ O ’ , ’ O ’ , ’ M ’ , ’ I ’ , ’ N ’ , ’
G ’ )
( ‘ G’ , ’ N’ , ’ I ’ , ’ M’ , ’ O’ , ’
O’ , ’ Z’ ) ( ‘ O ’ , ’ M ’ , ’ I ’ )
Slicing of Tuples
• Tuples are immutable and hence
they do not allow deletion of a part of
it.
• Entire tuple gets deleted by the use of
del() method.
• Note- Printing of Tuple after
deletion results to an Error.
# Deleting a Tuple
Tuple1 = (0, 1, 2, 3, 4)
del Tuple1
print(Tuple1)
NameError: name ‘Tuple1’is not defined
Deleting
BUILT-IN FUNCTION DESCRIPTION
all() Returns true if all element are true or if tuple is empty
any() return true if any element of the tuple is true. if tuple is empty, return false
len() Returns length of the tuple or size of the tuple
enumerate() Returns enumerate object of tuple
max() return maximum element of given tuple
min() return minimum element of given tuple
sum() Sums up the numbers in the tuple
sorted() input elements in the tuple and return a new sorted list
tuple() Convert an iterable to a tuple.
Built-In-Methods in Tuples
o Python dictionary is an unordered collection of items.
o While other compound data types have only value as an element,
a dictionary has a key: value pair.
o Dictionaries are optimized to retrieve values when the key is known.
Python Dictionary
o Creating A Dictionary Is As Simple As Placing Items Inside
Curly Braces {} Separated By Comma.
o Each element in a dictionary is represented by a key:value pair.
o While values can be of any data type and can repeat,
o keys must be of immutable type and must be unique.
Creation of Dictionary
o While indexing is used with other container types to access values, dictionary uses keys.
Key can be used either inside square brackets or with the get() method.
o The difference while using get() is that it returns None instead of KeyError, if the
key is not found.
Accessing an elements
from an Dictionary
o We can remove a particular item in a dictionary by using the method pop(). This
method removes as item with the provided key and returns the value.
o All the items can be removed at once using the clear() method.
o We can also use the del keyword to remove individual items or the entire dictionary
itself.
Deletion from Dictionary
THANK YOU!!

More Related Content

What's hot (20)

Lists
ListsLists
Lists
 
Python programming : List and tuples
Python programming : List and tuplesPython programming : List and tuples
Python programming : List and tuples
 
Data Structures in Python
Data Structures in PythonData Structures in Python
Data Structures in Python
 
Sets in python
Sets in pythonSets in python
Sets in python
 
Matplotlib
MatplotlibMatplotlib
Matplotlib
 
Visualization and Matplotlib using Python.pptx
Visualization and Matplotlib using Python.pptxVisualization and Matplotlib using Python.pptx
Visualization and Matplotlib using Python.pptx
 
Arrays in python
Arrays in pythonArrays in python
Arrays in python
 
Python programming : Arrays
Python programming : ArraysPython programming : Arrays
Python programming : Arrays
 
Dictionary
DictionaryDictionary
Dictionary
 
Python-List.pptx
Python-List.pptxPython-List.pptx
Python-List.pptx
 
Queue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListQueue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked List
 
Python : Data Types
Python : Data TypesPython : Data Types
Python : Data Types
 
Chapter 17 Tuples
Chapter 17 TuplesChapter 17 Tuples
Chapter 17 Tuples
 
Linked list
Linked listLinked list
Linked list
 
Stacks Implementation and Examples
Stacks Implementation and ExamplesStacks Implementation and Examples
Stacks Implementation and Examples
 
Python Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionaryPython Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, Dictionary
 
What Are Python Modules? Edureka
What Are Python Modules? EdurekaWhat Are Python Modules? Edureka
What Are Python Modules? Edureka
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionary
 

Similar to Python Collections

Basic data structures in python
Basic data structures in pythonBasic data structures in python
Basic data structures in pythonCeline George
 
PYTHON LISTsjnjsnljnsjnosojnosojnsojnsjsn.pptx
PYTHON LISTsjnjsnljnsjnosojnosojnsojnsjsn.pptxPYTHON LISTsjnjsnljnsjnosojnosojnsojnsjsn.pptx
PYTHON LISTsjnjsnljnsjnosojnosojnsojnsjsn.pptxsurajnath20
 
11 Introduction to lists.pptx
11 Introduction to lists.pptx11 Introduction to lists.pptx
11 Introduction to lists.pptxssuser8e50d8
 
Anton Kasyanov, Introduction to Python, Lecture4
Anton Kasyanov, Introduction to Python, Lecture4Anton Kasyanov, Introduction to Python, Lecture4
Anton Kasyanov, Introduction to Python, Lecture4Anton Kasyanov
 
computer science tuple in python project.pdf
computer science tuple in python project.pdfcomputer science tuple in python project.pdf
computer science tuple in python project.pdfREXGAMING6
 
RANDOMISATION-NUMERICAL METHODS FOR ENGINEERING.pptx
RANDOMISATION-NUMERICAL METHODS  FOR ENGINEERING.pptxRANDOMISATION-NUMERICAL METHODS  FOR ENGINEERING.pptx
RANDOMISATION-NUMERICAL METHODS FOR ENGINEERING.pptxOut Cast
 
02 Python Data Structure.pptx
02 Python Data Structure.pptx02 Python Data Structure.pptx
02 Python Data Structure.pptxssuser88c564
 
Python data type
Python data typePython data type
Python data typeJaya Kumari
 
Data types in python
Data types in pythonData types in python
Data types in pythonRaginiJain21
 
Introduction of Python-1.pdf
Introduction of Python-1.pdfIntroduction of Python-1.pdf
Introduction of Python-1.pdfSyamsulFattanSSos
 
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
 

Similar to Python Collections (20)

Python revision tour II
Python revision tour IIPython revision tour II
Python revision tour II
 
Basic data structures in python
Basic data structures in pythonBasic data structures in python
Basic data structures in python
 
tupple.pptx
tupple.pptxtupple.pptx
tupple.pptx
 
Tuples-and-Dictionaries.pptx
Tuples-and-Dictionaries.pptxTuples-and-Dictionaries.pptx
Tuples-and-Dictionaries.pptx
 
PYTHON LISTsjnjsnljnsjnosojnosojnsojnsjsn.pptx
PYTHON LISTsjnjsnljnsjnosojnosojnsojnsjsn.pptxPYTHON LISTsjnjsnljnsjnosojnosojnsojnsjsn.pptx
PYTHON LISTsjnjsnljnsjnosojnosojnsojnsjsn.pptx
 
11 Introduction to lists.pptx
11 Introduction to lists.pptx11 Introduction to lists.pptx
11 Introduction to lists.pptx
 
Anton Kasyanov, Introduction to Python, Lecture4
Anton Kasyanov, Introduction to Python, Lecture4Anton Kasyanov, Introduction to Python, Lecture4
Anton Kasyanov, Introduction to Python, Lecture4
 
updated_tuple_in_python.pdf
updated_tuple_in_python.pdfupdated_tuple_in_python.pdf
updated_tuple_in_python.pdf
 
computer science tuple in python project.pdf
computer science tuple in python project.pdfcomputer science tuple in python project.pdf
computer science tuple in python project.pdf
 
Pytho_tuples
Pytho_tuplesPytho_tuples
Pytho_tuples
 
RANDOMISATION-NUMERICAL METHODS FOR ENGINEERING.pptx
RANDOMISATION-NUMERICAL METHODS  FOR ENGINEERING.pptxRANDOMISATION-NUMERICAL METHODS  FOR ENGINEERING.pptx
RANDOMISATION-NUMERICAL METHODS FOR ENGINEERING.pptx
 
02 Python Data Structure.pptx
02 Python Data Structure.pptx02 Python Data Structure.pptx
02 Python Data Structure.pptx
 
Python data type
Python data typePython data type
Python data type
 
Data types in python
Data types in pythonData types in python
Data types in python
 
Introduction of Python-1.pdf
Introduction of Python-1.pdfIntroduction of Python-1.pdf
Introduction of Python-1.pdf
 
Python data handling notes
Python data handling notesPython data handling notes
Python data handling notes
 
Lists_tuples.pptx
Lists_tuples.pptxLists_tuples.pptx
Lists_tuples.pptx
 
Python list
Python listPython list
Python list
 
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
 

Recently uploaded

Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
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
 
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
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
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
 
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
 
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
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
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
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 

Recently uploaded (20)

Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
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
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
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
 
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
 
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
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
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
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 

Python Collections

  • 1. By: Sachin Garg CT University
  • 2. There are four collection data types in the Python programming language: o List is a collection which is ordered and changeable. Allows duplicate members. o Tuple is a collection which is ordered and unchangeable. Allows duplicate members. o Dictionary is a collection which is unordered, changeable and indexed. No duplicate members. Python Collections (Arrays)
  • 3. A list is created by placing all the items (elements) inside a square bracket [ ], separated by commas. It can have any number of items and they may be of different types (integer, float, string etc.). Example: list = [1, 2, 3] # list with same data-types list = [1, "Hello", 3.4] # list with mixed data-types List Creation
  • 4.  It can be access in several ways  Use the index operator [] to access an item in a list. Index starts from 0. So, a list having 5 elements will have index from 0 to 4.  Example: list = ['p','r','o','b','e'] Output O bprint(list[2]) #Positive Indexing b print(list[-2]) #Negative Indexing Access Items From List
  • 5.  Accessing a range of items in a list by using the slicing operator [ ] using (colon :).  Slicing can be best visualized by considering the index to be between the elements.  Example: list = ['p','r','o','b','e'] print(list[0:4]) #Positive print(list[-2:-1]) # Negative Output ['p', 'r', 'o', 'b'] ['b'] 4 Slice List
  • 6.  append()  count() - Add an element to the end of the list. - Returns the count of number of items passed as an argument. - Add all elements of a list to the another list. - Returns the index of the first matched item. - Insert an item at the defined index. - Removes and returns an element at the given index. - Returns a shallow copy of the list - Removes an item from the list. - Reverse the order of items in the list.  extend()  index()  insert()  pop()  copy()  remove()  reverse()  sort() - Sort items in a list in ascending order. 5 List Methods
  • 7. • It is a collection of object much like a list. • The main different between tuple and list is that tuples are immutable. • It represent as ( ). • Values of a tuple are syntactically separated by commas. • Tuple elements cannot be changes. Tuples
  • 8. Tuple1 = ( ) //empty tuple Tuple2 = ('zooming', 'For ’) //tuple with strings l i s t 1 = [1, 2, 4, 5, 6] Tuple 3 = tuple ( l i s t 1 ) //tuple with the use of l i s t Tuple 4 = (‘zooming’,) * 3 //tuple with repetition Tuple 5 = (5, 'Welcome', 7, ‘zooming’) //tuple with mixed datatypes Creation of Tuples
  • 9. • Concatenation of tuple is the process of joining of two or more Tuples. • Concatenation is done by theuse of ‘+’ operator. • Concatenationof tuples is done always from the end of the original tuple. • Other arithmetic operations do not apply on Tuples. # Concatenaton of tuples Tuple1 = (0, 1, 2, 3) Tuple2 = (‘Zooming', 'For', ‘stud') Tuple3 = Tuple1 + Tuple2 print("nTuples after Concatenaton: " ) print(Tuple3) Tuples aft er Concatenaton: ( 0 , 1, 2, 3, ‘Zooming', ' F o r ' , ‘ s t u d ' ) Concatenation of Tuples
  • 10. # with Numbers Tuple1 = tuple(‘ZOOMING') # From First element print(Tuple1[1:]) # Reversing the Tuple print(Tuple1[::-1]) # Printing elements of a Range print(Tuple1[2:5]) ( ‘ O ’ , ’ O ’ , ’ M ’ , ’ I ’ , ’ N ’ , ’ G ’ ) ( ‘ G’ , ’ N’ , ’ I ’ , ’ M’ , ’ O’ , ’ O’ , ’ Z’ ) ( ‘ O ’ , ’ M ’ , ’ I ’ ) Slicing of Tuples
  • 11. • Tuples are immutable and hence they do not allow deletion of a part of it. • Entire tuple gets deleted by the use of del() method. • Note- Printing of Tuple after deletion results to an Error. # Deleting a Tuple Tuple1 = (0, 1, 2, 3, 4) del Tuple1 print(Tuple1) NameError: name ‘Tuple1’is not defined Deleting
  • 12. BUILT-IN FUNCTION DESCRIPTION all() Returns true if all element are true or if tuple is empty any() return true if any element of the tuple is true. if tuple is empty, return false len() Returns length of the tuple or size of the tuple enumerate() Returns enumerate object of tuple max() return maximum element of given tuple min() return minimum element of given tuple sum() Sums up the numbers in the tuple sorted() input elements in the tuple and return a new sorted list tuple() Convert an iterable to a tuple. Built-In-Methods in Tuples
  • 13. o Python dictionary is an unordered collection of items. o While other compound data types have only value as an element, a dictionary has a key: value pair. o Dictionaries are optimized to retrieve values when the key is known. Python Dictionary
  • 14. o Creating A Dictionary Is As Simple As Placing Items Inside Curly Braces {} Separated By Comma. o Each element in a dictionary is represented by a key:value pair. o While values can be of any data type and can repeat, o keys must be of immutable type and must be unique. Creation of Dictionary
  • 15. o While indexing is used with other container types to access values, dictionary uses keys. Key can be used either inside square brackets or with the get() method. o The difference while using get() is that it returns None instead of KeyError, if the key is not found. Accessing an elements from an Dictionary
  • 16. o We can remove a particular item in a dictionary by using the method pop(). This method removes as item with the provided key and returns the value. o All the items can be removed at once using the clear() method. o We can also use the del keyword to remove individual items or the entire dictionary itself. Deletion from Dictionary