SlideShare a Scribd company logo
1 of 17
LIST IN PYTHON
COMPUTER SCIENCE -083
ACCESSING LIST ELEMENTS
Accessing List Elements
A list is a collection of items which are stored according to its index. Its work like String.
The values stored in a list can be accessed using the slice operator ([ ] and [:]) with indexes.
List-name [start: end] will give you elements between indices start to end-1.
The first item in the list has the index zero (0).
Accessing List Elements
Example:
Let’s store no’s in a list
no=[10,20,30,40,50,60,70,80]
0 1 2 3 4 5 6 7
10 20 30 40 50 60 70 80
-8 -7 -6 -5 -4 -3 -2 -1
Positive index
Negative index
Accessing List Elements
Positive index
Negative index
Example:
Let’s store Month’s in a list
month=[‘JAN’,’FEB’,’MAR’,’APR’,’MAY’,’JUN’,’JUL’,’AUG’,’SEP’,’OCT’,’NOV’,’DEC’]
0 1 2 3 4 5 6 7 8 9 10 11
JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC
-12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1
Now To access these list let us discuss
operations of list
List operations
Indexing Slicing Repetition Concatenation Membership Testing
These operators we discuss in the String video also
Indexing
Indexing specify the position of elements in a list or sequence and help us
to access the value from the sequence separately.
For Example:
if we want to access the number 50 from a list given below using positive
index number.
0 1 2 3 4 5 6 7
10 20 30 40 50 60 70 80
-8 -7 -6 -5 -4 -3 -2 -1
Positive index
Negative index
Indexing
0 1 2 3 4 5 6 7
10 20 30 40 50 60 70 80
-8 -7 -6 -5 -4 -3 -2 -1
Positive index
Negative index
no=[10,20,30,40,50,60,70,80]
print(no[4])
--------output--------
50
if we want to access the number 30 from a list given below
using negative index number.
no=[10,20,30,40,50,60,70,80]
print(no[-6])
--------output-------------
30
Slicing
Slicing and indexing are two inter-related operations in lists. Slicing is an
operation in which you can slice a particular range from a sequence.
Syntax:
listname [start : stop : step]
Where, start is the starting point
Stop is the stopping point
Step is the step size—also known as stride, and is optional. Its default value is 1
Slicing
Now let Us take one Example:
mylist=[100,”Suraj”,50.45,”pratap”,450,890.25]
0 1 2 3 4 5
100 Suraj 50.45 pratap 450 890.25
-6 -5 -4 -3 -2 -1
print ( mylist [ : ] ) 100,”Suraj”,50.45,”pratap”,450,890.25
All the values
print ( mylist [ 1 : 4 ] ) ['Suraj', 50.45, 'pratap']
Items from 1 to 3
Slicing
Now let Us take one Example:
mylist=[100,”Suraj”,50.45,”pratap”,450,890.25]
0 1 2 3 4 5
100 Suraj 50.45 pratap 450 890.25
-6 -5 -4 -3 -2 -1
print(mylist[1:6:2]) ['Suraj', 'pratap', 890.25]
Items 1,3,5
print(mylist[-3:]) ['pratap', 450, 890.25]
Last 3 items
Steps: By default 1 step jump , bur if we make that 2 it means jump of two
Concatenation
It is a process in which lists can be combine together with the help of ‘+’
operator.
Example: list1=[10,20,30]
list2=[1,2,3]
In this list1 we add list2 and original list1 overwrite
list1=list1+list2
------------output--------------
[10, 20, 30, 1, 2, 3]
Repetition
Multiply ( * asterisk) operator replicates the list for specified number of
times.
Example: list1=[10,20,30]
print(list1*2)
------------output--------------
[10, 20, 30, 10, 20, 30]
It check whether a particular element or item is a member of that sequence or
list or not.
There are two operator:
1. in operator 2. not in operator
Membership Testing:
in operator:
It returns true if element appears
in the list, otherwise returns false.
Example:
list1=[10,20,30,40]
print(10 in list1)
----------output-----------
True
Note: it will give True if value not
exists inside the list
not in operator: It returns true if element not appears in the list, otherwise
returns false.
Example:
list1=[10,20,30,40]
print(3 not in list1)
----------output-----------
True
How to use arithmetic operators in list
Plus: (+) minus: (-) multiply: (*)
divide: (/)
0 1 2 3 4 5 6 7
10 20 30 40 50 60 70 80
Now if we need to modify the value of 40 at index no. 3 by adding 15 to it.
no=[10,20,30,40,50,60,70,80]
no=no+15no[3]=15
print(no)
[10,20,30,15,50,60,70,80]
0 1 2 3 4 5 6 7
10 20 30 40 50 60 70 80
Now if we need to modify the value of 40 at index no. 3 by adding 15 to it.
no=[10,20,30,40,50,60,70,80]
no[3]=no[3]+15
print(no)
[10,20,30,55,50,60,70,80]

More Related Content

What's hot

The Ring programming language version 1.9 book - Part 29 of 210
The Ring programming language version 1.9 book - Part 29 of 210The Ring programming language version 1.9 book - Part 29 of 210
The Ring programming language version 1.9 book - Part 29 of 210Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 27 of 202
The Ring programming language version 1.8 book - Part 27 of 202The Ring programming language version 1.8 book - Part 27 of 202
The Ring programming language version 1.8 book - Part 27 of 202Mahmoud Samir Fayed
 
Python Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionaryPython Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionarySoba Arjun
 
The Ring programming language version 1.5.3 book - Part 22 of 184
The Ring programming language version 1.5.3 book - Part 22 of 184The Ring programming language version 1.5.3 book - Part 22 of 184
The Ring programming language version 1.5.3 book - Part 22 of 184Mahmoud Samir Fayed
 
Python programming -Tuple and Set Data type
Python programming -Tuple and Set Data typePython programming -Tuple and Set Data type
Python programming -Tuple and Set Data typeMegha V
 
List and Dictionary in python
List and Dictionary in pythonList and Dictionary in python
List and Dictionary in pythonSangita Panchal
 
Arrays in python
Arrays in pythonArrays in python
Arrays in pythonLifna C.S
 
Python Workshop Part 2. LUG Maniapl
Python Workshop Part 2. LUG ManiaplPython Workshop Part 2. LUG Maniapl
Python Workshop Part 2. LUG ManiaplAnkur Shrivastava
 

What's hot (20)

The Ring programming language version 1.9 book - Part 29 of 210
The Ring programming language version 1.9 book - Part 29 of 210The Ring programming language version 1.9 book - Part 29 of 210
The Ring programming language version 1.9 book - Part 29 of 210
 
Python lists & sets
Python lists & setsPython lists & sets
Python lists & sets
 
The Ring programming language version 1.8 book - Part 27 of 202
The Ring programming language version 1.8 book - Part 27 of 202The Ring programming language version 1.8 book - Part 27 of 202
The Ring programming language version 1.8 book - Part 27 of 202
 
Python Programming Essentials - M12 - Lists
Python Programming Essentials - M12 - ListsPython Programming Essentials - M12 - Lists
Python Programming Essentials - M12 - Lists
 
Python lists
Python listsPython lists
Python lists
 
Python Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionaryPython Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, Dictionary
 
The Ring programming language version 1.5.3 book - Part 22 of 184
The Ring programming language version 1.5.3 book - Part 22 of 184The Ring programming language version 1.5.3 book - Part 22 of 184
The Ring programming language version 1.5.3 book - Part 22 of 184
 
Python programming -Tuple and Set Data type
Python programming -Tuple and Set Data typePython programming -Tuple and Set Data type
Python programming -Tuple and Set Data type
 
Python programming : List and tuples
Python programming : List and tuplesPython programming : List and tuples
Python programming : List and tuples
 
Lists
ListsLists
Lists
 
Pytho lists
Pytho listsPytho lists
Pytho lists
 
Pytho_tuples
Pytho_tuplesPytho_tuples
Pytho_tuples
 
1 D Arrays in C++
1 D Arrays in C++1 D Arrays in C++
1 D Arrays in C++
 
2- Dimensional Arrays
2- Dimensional Arrays2- Dimensional Arrays
2- Dimensional Arrays
 
List and Dictionary in python
List and Dictionary in pythonList and Dictionary in python
List and Dictionary in python
 
Arrays in python
Arrays in pythonArrays in python
Arrays in python
 
Python Workshop Part 2. LUG Maniapl
Python Workshop Part 2. LUG ManiaplPython Workshop Part 2. LUG Maniapl
Python Workshop Part 2. LUG Maniapl
 
1-D array
1-D array1-D array
1-D array
 
1 pythonbasic
1 pythonbasic1 pythonbasic
1 pythonbasic
 
2D Array
2D Array 2D Array
2D Array
 

Similar to LIST IN PYTHON PART-2

Similar to LIST IN PYTHON PART-2 (20)

PYTHON.pptx
PYTHON.pptxPYTHON.pptx
PYTHON.pptx
 
Module-2.pptx
Module-2.pptxModule-2.pptx
Module-2.pptx
 
python_avw - Unit-03.pdf
python_avw - Unit-03.pdfpython_avw - Unit-03.pdf
python_avw - Unit-03.pdf
 
Lecture2.pptx
Lecture2.pptxLecture2.pptx
Lecture2.pptx
 
Python list
Python listPython list
Python list
 
List_tuple_dictionary.pptx
List_tuple_dictionary.pptxList_tuple_dictionary.pptx
List_tuple_dictionary.pptx
 
Python for Beginners(v3)
Python for Beginners(v3)Python for Beginners(v3)
Python for Beginners(v3)
 
Python list concept
Python list conceptPython list concept
Python list concept
 
Unit - 4.ppt
Unit - 4.pptUnit - 4.ppt
Unit - 4.ppt
 
Python Unit 5 Questions n Notes.pdf
Python Unit 5 Questions n Notes.pdfPython Unit 5 Questions n Notes.pdf
Python Unit 5 Questions n Notes.pdf
 
List Data Structure.docx
List Data Structure.docxList Data Structure.docx
List Data Structure.docx
 
‏‏chap6 list tuples.pptx
‏‏chap6 list tuples.pptx‏‏chap6 list tuples.pptx
‏‏chap6 list tuples.pptx
 
Python Programming: Lists, Modules, Exceptions
Python Programming: Lists, Modules, ExceptionsPython Programming: Lists, Modules, Exceptions
Python Programming: Lists, Modules, Exceptions
 
Module III.pdf
Module III.pdfModule III.pdf
Module III.pdf
 
6. list
6. list6. list
6. list
 
Python-List.pptx
Python-List.pptxPython-List.pptx
Python-List.pptx
 
arrays.pptx
arrays.pptxarrays.pptx
arrays.pptx
 
Lists.pptx
Lists.pptxLists.pptx
Lists.pptx
 
Python list 28_10_2020
Python list 28_10_2020Python list 28_10_2020
Python list 28_10_2020
 
The Ring programming language version 1.10 book - Part 30 of 212
The Ring programming language version 1.10 book - Part 30 of 212The Ring programming language version 1.10 book - Part 30 of 212
The Ring programming language version 1.10 book - Part 30 of 212
 

More from vikram mahendra

Python Project On Cosmetic Shop system
Python Project On Cosmetic Shop systemPython Project On Cosmetic Shop system
Python Project On Cosmetic Shop systemvikram mahendra
 
Python Project on Computer Shop
Python Project on Computer ShopPython Project on Computer Shop
Python Project on Computer Shopvikram mahendra
 
PYTHON PROJECT ON CARSHOP SYSTEM
PYTHON PROJECT ON CARSHOP SYSTEMPYTHON PROJECT ON CARSHOP SYSTEM
PYTHON PROJECT ON CARSHOP SYSTEMvikram mahendra
 
BOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in PythonBOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in Pythonvikram mahendra
 
FLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHONFLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHONvikram mahendra
 
FLOWOFCONTROL-IF..ELSE PYTHON
FLOWOFCONTROL-IF..ELSE PYTHONFLOWOFCONTROL-IF..ELSE PYTHON
FLOWOFCONTROL-IF..ELSE PYTHONvikram mahendra
 
FLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHONFLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHONvikram mahendra
 
OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1vikram mahendra
 
OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2vikram mahendra
 
USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2vikram mahendra
 
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]vikram mahendra
 
USER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHONUSER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHONvikram mahendra
 
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]vikram mahendra
 
INTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHONINTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHONvikram mahendra
 

More from vikram mahendra (20)

Communication skill
Communication skillCommunication skill
Communication skill
 
Python Project On Cosmetic Shop system
Python Project On Cosmetic Shop systemPython Project On Cosmetic Shop system
Python Project On Cosmetic Shop system
 
Python Project on Computer Shop
Python Project on Computer ShopPython Project on Computer Shop
Python Project on Computer Shop
 
PYTHON PROJECT ON CARSHOP SYSTEM
PYTHON PROJECT ON CARSHOP SYSTEMPYTHON PROJECT ON CARSHOP SYSTEM
PYTHON PROJECT ON CARSHOP SYSTEM
 
BOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in PythonBOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in Python
 
FLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHONFLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHON
 
FLOWOFCONTROL-IF..ELSE PYTHON
FLOWOFCONTROL-IF..ELSE PYTHONFLOWOFCONTROL-IF..ELSE PYTHON
FLOWOFCONTROL-IF..ELSE PYTHON
 
FLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHONFLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHON
 
OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1
 
OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2
 
USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2
 
DATA TYPE IN PYTHON
DATA TYPE IN PYTHONDATA TYPE IN PYTHON
DATA TYPE IN PYTHON
 
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
 
USER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHONUSER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHON
 
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
 
INTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHONINTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHON
 
Python Introduction
Python IntroductionPython Introduction
Python Introduction
 
GREEN SKILL[PART-2]
GREEN SKILL[PART-2]GREEN SKILL[PART-2]
GREEN SKILL[PART-2]
 
GREEN SKILLS[PART-1]
GREEN SKILLS[PART-1]GREEN SKILLS[PART-1]
GREEN SKILLS[PART-1]
 
Dictionary in python
Dictionary in pythonDictionary in python
Dictionary in python
 

Recently uploaded

Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 

Recently uploaded (20)

Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 

LIST IN PYTHON PART-2

  • 1. LIST IN PYTHON COMPUTER SCIENCE -083 ACCESSING LIST ELEMENTS
  • 2. Accessing List Elements A list is a collection of items which are stored according to its index. Its work like String. The values stored in a list can be accessed using the slice operator ([ ] and [:]) with indexes. List-name [start: end] will give you elements between indices start to end-1. The first item in the list has the index zero (0).
  • 3. Accessing List Elements Example: Let’s store no’s in a list no=[10,20,30,40,50,60,70,80] 0 1 2 3 4 5 6 7 10 20 30 40 50 60 70 80 -8 -7 -6 -5 -4 -3 -2 -1 Positive index Negative index
  • 4. Accessing List Elements Positive index Negative index Example: Let’s store Month’s in a list month=[‘JAN’,’FEB’,’MAR’,’APR’,’MAY’,’JUN’,’JUL’,’AUG’,’SEP’,’OCT’,’NOV’,’DEC’] 0 1 2 3 4 5 6 7 8 9 10 11 JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1
  • 5. Now To access these list let us discuss operations of list List operations Indexing Slicing Repetition Concatenation Membership Testing These operators we discuss in the String video also
  • 6. Indexing Indexing specify the position of elements in a list or sequence and help us to access the value from the sequence separately. For Example: if we want to access the number 50 from a list given below using positive index number. 0 1 2 3 4 5 6 7 10 20 30 40 50 60 70 80 -8 -7 -6 -5 -4 -3 -2 -1 Positive index Negative index
  • 7. Indexing 0 1 2 3 4 5 6 7 10 20 30 40 50 60 70 80 -8 -7 -6 -5 -4 -3 -2 -1 Positive index Negative index no=[10,20,30,40,50,60,70,80] print(no[4]) --------output-------- 50 if we want to access the number 30 from a list given below using negative index number. no=[10,20,30,40,50,60,70,80] print(no[-6]) --------output------------- 30
  • 8. Slicing Slicing and indexing are two inter-related operations in lists. Slicing is an operation in which you can slice a particular range from a sequence. Syntax: listname [start : stop : step] Where, start is the starting point Stop is the stopping point Step is the step size—also known as stride, and is optional. Its default value is 1
  • 9. Slicing Now let Us take one Example: mylist=[100,”Suraj”,50.45,”pratap”,450,890.25] 0 1 2 3 4 5 100 Suraj 50.45 pratap 450 890.25 -6 -5 -4 -3 -2 -1 print ( mylist [ : ] ) 100,”Suraj”,50.45,”pratap”,450,890.25 All the values print ( mylist [ 1 : 4 ] ) ['Suraj', 50.45, 'pratap'] Items from 1 to 3
  • 10. Slicing Now let Us take one Example: mylist=[100,”Suraj”,50.45,”pratap”,450,890.25] 0 1 2 3 4 5 100 Suraj 50.45 pratap 450 890.25 -6 -5 -4 -3 -2 -1 print(mylist[1:6:2]) ['Suraj', 'pratap', 890.25] Items 1,3,5 print(mylist[-3:]) ['pratap', 450, 890.25] Last 3 items Steps: By default 1 step jump , bur if we make that 2 it means jump of two
  • 11. Concatenation It is a process in which lists can be combine together with the help of ‘+’ operator. Example: list1=[10,20,30] list2=[1,2,3] In this list1 we add list2 and original list1 overwrite list1=list1+list2 ------------output-------------- [10, 20, 30, 1, 2, 3]
  • 12. Repetition Multiply ( * asterisk) operator replicates the list for specified number of times. Example: list1=[10,20,30] print(list1*2) ------------output-------------- [10, 20, 30, 10, 20, 30]
  • 13. It check whether a particular element or item is a member of that sequence or list or not. There are two operator: 1. in operator 2. not in operator Membership Testing: in operator: It returns true if element appears in the list, otherwise returns false. Example: list1=[10,20,30,40] print(10 in list1) ----------output----------- True
  • 14. Note: it will give True if value not exists inside the list not in operator: It returns true if element not appears in the list, otherwise returns false. Example: list1=[10,20,30,40] print(3 not in list1) ----------output----------- True
  • 15. How to use arithmetic operators in list Plus: (+) minus: (-) multiply: (*) divide: (/)
  • 16. 0 1 2 3 4 5 6 7 10 20 30 40 50 60 70 80 Now if we need to modify the value of 40 at index no. 3 by adding 15 to it. no=[10,20,30,40,50,60,70,80] no=no+15no[3]=15 print(no) [10,20,30,15,50,60,70,80]
  • 17. 0 1 2 3 4 5 6 7 10 20 30 40 50 60 70 80 Now if we need to modify the value of 40 at index no. 3 by adding 15 to it. no=[10,20,30,40,50,60,70,80] no[3]=no[3]+15 print(no) [10,20,30,55,50,60,70,80]