SlideShare a Scribd company logo
2
Most read
7
Most read
15
Most read
PYTHON LIST
By A. A. Bhumkar
PYTHON LIST
1).Python lists are the data structure that is capable of
holding different type of data.
2).Python lists are mutable i.e., Python will not create a
new list if we modify an element in the list.
3).It is a container that holds other objects in a given order.
Different operation like insertion and deletion can be
performed on lists.
4).A list can be composed by storing a sequence of
different type of values separated by commas.
5).A python list is enclosed between square([]) brackets.
6).The elements are stored in the index basis with starting
index as 0.
CREATING LIST
 A list can be created by putting the value inside the
square bracket and separated by comma.
 Syntax:
<list_name>=[value1,value2,value3,...,valuen];
 For accessing list :
<list_name>[index]
ELEMENTS IN A LISTS:
Data=[1,2,3,4,5];
LIST OPERATIONS:
a) Adding Lists:
Lists can be added by using the concatenation operator(+)
to join two lists.
Eg:
list1=[10,20]
list2=[30,40]
list3=list1+list2
print list3 Output:
>>>
[10, 20, 30, 40]
>>>
b) Replicating lists:
Replicating means repeating . It can be performed by
using '*' operator by a specific number of time.
Eg:
list1=[10,20]
print list1*1
Output:
>>>
[10, 20]
>>>
c) List slicing:
A subpart of a list can be retrieved on the basis of index.
This subpart is known as list slice.
Eg:
list1=[1,2,4,5,7]
print list1[0:2]
print list1[4]
list1[1]=9
print list1
Output:
>>>
[1, 2]
7
[1, 9, 4, 5, 7]
>>>
OTHER OPERATIONS:
a) Updating elements in a List:
To update or change the value of particular index of a list,
assign the value to that particular index of the List.
Syntax:
<list_name>[index]=<value>
Eg.
>>> list=[1,2,3,4]
>>> list[2]="Hello Python"
>>> print(list)
[1, 2, 'Hello Python', 4]
>>>
b) Appending elements to a List:
append() method is used to append i.e., add an element at
the end of the existing elements.
Syntax:
<list_name>.append(item)
Eg.
>>> list=[1,2,3,4]
>>> list.append(40)
>>> print(list)
[1, 2, 3, 4, 40]
>>>
c) Deleting Elements from a List:
del statement can be used to delete an element from the
list. It can also be used to delete all items from
startIndex to endIndex.
Eg.
>>> list = [1,2,3,4]
>>> del list[2]
>>> print(list)
[1, 2, 4]
FUNCTIONS AND METHODS OF LISTS:
Function Description Example
min(list)
Returns the minimum
value from the list
given.
>>> list=[1,2,3,4,5]
>>> min(list)
1
max(list)
Returns the largest
value from the given
list.
>>> list=[1,2,3,4,5]
>>> max(list)
5
len(list)
Returns number of
elements in a list.
>>> list=[1,2,3,4,5]
>>> len(list)
5
Methods Description Example
index(object)
Returns the index value of the
object.
>>> l = ['a','b','c','d']
>>>l.index(‘a’)
>>>0
count(object)
It returns the number of times an
object is repeated in list.
>>> l = [1,2,3,1,4,5,1]
>>> l.count(1)
3
pop()/pop(index)
Returns the last object or the
specified indexed object. It
removes the popped object.
>>> l = [1,2,3,1,4,5,1]
>>> l.pop()
1
>>> print(list)
[1, 2, 3, 4, 5]
>>> l.pop(3)
1
>>> print(l)
[1, 2, 3, 4, 5]
Methods Description Example
insert(index,object)
Insert an object at the
given index.
>>>l=[1,2,3,4,5]
>>> l.insert(3,11)
>>> print(l)
[1, 2, 3, 11, 4, 5]
extend(sequence)
It adds the sequence to
existing list.
>>>l=[1, 2, 3, 11, 4, 5]
>>> seq = (12,13)
>>> l.extend(seq)
>>> print(l)
[1, 2, 3, 11, 4, 5, 12, 13]
remove(object)
It removes the object
from the given List.
>>>l=[1, 2, 3, 11, 4, 5, 12,
13]
>>> l.remove(12)
>>> print(l)
[1, 2, 3, 11, 4, 5, 13]
Methods Description
Example
reverse()
Reverse the position of all the
elements of a list.
>>>l=[1, 2, 3, 11, 4, 5, 13]
>>> l.reverse()
>>> print(l)
[13, 5, 4, 11, 3, 2, 1]
sort()
It is used to sort the elements
of the List.
>>> l = [2,4,1,5,3]
>>> l.sort()
>>> print(l)
[1, 2, 3, 4, 5]
THANK YOU !!!

More Related Content

PPTX
Python - Data Structures
PPTX
Python Collections
PPTX
Unit 4 python -list methods
PPTX
List in Python
PDF
List , tuples, dictionaries and regular expressions in python
PPTX
Chapter 17 Tuples
PDF
Python programming : List and tuples
PDF
8 python data structure-1
Python - Data Structures
Python Collections
Unit 4 python -list methods
List in Python
List , tuples, dictionaries and regular expressions in python
Chapter 17 Tuples
Python programming : List and tuples
8 python data structure-1

What's hot (20)

PDF
Python list
PPTX
Datastructures in python
PDF
Python set
PPTX
List in Python
PDF
Python Variable Types, List, Tuple, Dictionary
PDF
Python Collections Tutorial | Edureka
PPTX
Tuple in python
PPTX
Stack and Queue
PPTX
Data Structures in Python
PDF
pandas - Python Data Analysis
PPTX
Values and Data types in python
PPTX
single linked list
PPT
Priority queues
PPTX
2D Array
PPTX
Regular expressions in Python
PDF
linked lists in data structures
PDF
Python Dictionary
PPTX
linked list in data structure
PPT
C++ Arrays
Python list
Datastructures in python
Python set
List in Python
Python Variable Types, List, Tuple, Dictionary
Python Collections Tutorial | Edureka
Tuple in python
Stack and Queue
Data Structures in Python
pandas - Python Data Analysis
Values and Data types in python
single linked list
Priority queues
2D Array
Regular expressions in Python
linked lists in data structures
Python Dictionary
linked list in data structure
C++ Arrays
Ad

Similar to Python list (20)

PPTX
list in python and traversal of list.pptx
PPTX
PYTHON-PROGRAMMING-UNIT-III.pptx kghbg kfhjf jruufg jtuuf
PPTX
Python - List, Dictionaries, Tuples,Sets
PDF
Data type list_methods_in_python
PPTX
updated_list.pptx
DOCX
List Data Structure.docx
PDF
Unit 1-Part-4-Lists, tuples and dictionaries.pdf
PPT
UNIT 4 PY.ppt - DATA STRUCTURE IN PYTHON
PPTX
Python list concept
PPTX
Python for the data science most in cse.pptx
PPTX
list.pptx
PDF
List in Python Using Back Developers in Using More Use.
PPTX
Chapter 15 Lists
PDF
List,tuple,dictionary
PPTX
Python _dataStructures_ List, Tuples, its functions
PPTX
Python lists
PDF
python_avw - Unit-03.pdf
PPTX
List In Python Programming. The linked list
list in python and traversal of list.pptx
PYTHON-PROGRAMMING-UNIT-III.pptx kghbg kfhjf jruufg jtuuf
Python - List, Dictionaries, Tuples,Sets
Data type list_methods_in_python
updated_list.pptx
List Data Structure.docx
Unit 1-Part-4-Lists, tuples and dictionaries.pdf
UNIT 4 PY.ppt - DATA STRUCTURE IN PYTHON
Python list concept
Python for the data science most in cse.pptx
list.pptx
List in Python Using Back Developers in Using More Use.
Chapter 15 Lists
List,tuple,dictionary
Python _dataStructures_ List, Tuples, its functions
Python lists
python_avw - Unit-03.pdf
List In Python Programming. The linked list
Ad

Recently uploaded (20)

PDF
composite construction of structures.pdf
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PPTX
Lecture Notes Electrical Wiring System Components
PPT
Mechanical Engineering MATERIALS Selection
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPT
Project quality management in manufacturing
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
Welding lecture in detail for understanding
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
Construction Project Organization Group 2.pptx
PDF
PPT on Performance Review to get promotions
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
Structs to JSON How Go Powers REST APIs.pdf
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
composite construction of structures.pdf
Strings in CPP - Strings in C++ are sequences of characters used to store and...
Lecture Notes Electrical Wiring System Components
Mechanical Engineering MATERIALS Selection
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Project quality management in manufacturing
CH1 Production IntroductoryConcepts.pptx
bas. eng. economics group 4 presentation 1.pptx
Operating System & Kernel Study Guide-1 - converted.pdf
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Welding lecture in detail for understanding
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Construction Project Organization Group 2.pptx
PPT on Performance Review to get promotions
OOP with Java - Java Introduction (Basics)
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Structs to JSON How Go Powers REST APIs.pdf
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
UNIT-1 - COAL BASED THERMAL POWER PLANTS

Python list

  • 1. PYTHON LIST By A. A. Bhumkar
  • 2. PYTHON LIST 1).Python lists are the data structure that is capable of holding different type of data. 2).Python lists are mutable i.e., Python will not create a new list if we modify an element in the list. 3).It is a container that holds other objects in a given order. Different operation like insertion and deletion can be performed on lists. 4).A list can be composed by storing a sequence of different type of values separated by commas. 5).A python list is enclosed between square([]) brackets. 6).The elements are stored in the index basis with starting index as 0.
  • 3. CREATING LIST  A list can be created by putting the value inside the square bracket and separated by comma.  Syntax: <list_name>=[value1,value2,value3,...,valuen];  For accessing list : <list_name>[index]
  • 4. ELEMENTS IN A LISTS: Data=[1,2,3,4,5];
  • 5. LIST OPERATIONS: a) Adding Lists: Lists can be added by using the concatenation operator(+) to join two lists. Eg: list1=[10,20] list2=[30,40] list3=list1+list2 print list3 Output: >>> [10, 20, 30, 40] >>>
  • 6. b) Replicating lists: Replicating means repeating . It can be performed by using '*' operator by a specific number of time. Eg: list1=[10,20] print list1*1 Output: >>> [10, 20] >>>
  • 7. c) List slicing: A subpart of a list can be retrieved on the basis of index. This subpart is known as list slice. Eg: list1=[1,2,4,5,7] print list1[0:2] print list1[4] list1[1]=9 print list1 Output: >>> [1, 2] 7 [1, 9, 4, 5, 7] >>>
  • 8. OTHER OPERATIONS: a) Updating elements in a List: To update or change the value of particular index of a list, assign the value to that particular index of the List. Syntax: <list_name>[index]=<value> Eg. >>> list=[1,2,3,4] >>> list[2]="Hello Python" >>> print(list) [1, 2, 'Hello Python', 4] >>>
  • 9. b) Appending elements to a List: append() method is used to append i.e., add an element at the end of the existing elements. Syntax: <list_name>.append(item) Eg. >>> list=[1,2,3,4] >>> list.append(40) >>> print(list) [1, 2, 3, 4, 40] >>>
  • 10. c) Deleting Elements from a List: del statement can be used to delete an element from the list. It can also be used to delete all items from startIndex to endIndex. Eg. >>> list = [1,2,3,4] >>> del list[2] >>> print(list) [1, 2, 4]
  • 11. FUNCTIONS AND METHODS OF LISTS: Function Description Example min(list) Returns the minimum value from the list given. >>> list=[1,2,3,4,5] >>> min(list) 1 max(list) Returns the largest value from the given list. >>> list=[1,2,3,4,5] >>> max(list) 5 len(list) Returns number of elements in a list. >>> list=[1,2,3,4,5] >>> len(list) 5
  • 12. Methods Description Example index(object) Returns the index value of the object. >>> l = ['a','b','c','d'] >>>l.index(‘a’) >>>0 count(object) It returns the number of times an object is repeated in list. >>> l = [1,2,3,1,4,5,1] >>> l.count(1) 3 pop()/pop(index) Returns the last object or the specified indexed object. It removes the popped object. >>> l = [1,2,3,1,4,5,1] >>> l.pop() 1 >>> print(list) [1, 2, 3, 4, 5] >>> l.pop(3) 1 >>> print(l) [1, 2, 3, 4, 5]
  • 13. Methods Description Example insert(index,object) Insert an object at the given index. >>>l=[1,2,3,4,5] >>> l.insert(3,11) >>> print(l) [1, 2, 3, 11, 4, 5] extend(sequence) It adds the sequence to existing list. >>>l=[1, 2, 3, 11, 4, 5] >>> seq = (12,13) >>> l.extend(seq) >>> print(l) [1, 2, 3, 11, 4, 5, 12, 13] remove(object) It removes the object from the given List. >>>l=[1, 2, 3, 11, 4, 5, 12, 13] >>> l.remove(12) >>> print(l) [1, 2, 3, 11, 4, 5, 13]
  • 14. Methods Description Example reverse() Reverse the position of all the elements of a list. >>>l=[1, 2, 3, 11, 4, 5, 13] >>> l.reverse() >>> print(l) [13, 5, 4, 11, 3, 2, 1] sort() It is used to sort the elements of the List. >>> l = [2,4,1,5,3] >>> l.sort() >>> print(l) [1, 2, 3, 4, 5]