SlideShare a Scribd company logo
1 of 25
LIST IN PYTHON
COMPUTER SCIENCE(083)
XII PART - 3
What is Built-in functions?
Built-in functions that predefined and supplied along with the compiler are
known as built-in functions. Inbuilt are those function which
already in the library and we did not need to create our own.
Let us discuss the built in functions of list
Built-in
operations
Append
Insert
Extend
Index
Sort
Reverse
Clear
Count
Deletion operation
Append It adds a single item to the end of the list
list_name.append( item or value)Syntax:
Example:
if we declare and initialize the list with numbers as shown below:
10 20 30 40
no=[10,20,30,40]
no.append(50)
print(no)
------------output-----------
10 20 30 40 50
0 1 2 3
0 1 2 3 4
The new element added at the end (Right side)
50
4
Insert
It can be used to insert an element or object at a specified index.
This function takes two arguments: the index where an item or
object is to be inserted and the item or element itself.
list_name.insert(index_no , value)
Syntax:
index_no : is the index where the new value is to be inserted
value: is the new value to be inserted in the list
Insert
Example:
If there are list in a python program no and numbers are 10, 20, 30 and
we want to new number 25 between 20 and 30 in a list no.
no= [10, 20, 30]
no.insert (2,25)
print(no)
----------output----------
0 1 2
10 20 30
10 20 25 30
0 1 2 3
0 1
10 20
2
25
2
30
3
Insert Example2:
If there are list in a python program names , names in a list are “Vinay”,
“Sonia”, “Deepak” and we want to new name “Kim” before “Vinay” in a
list name
names= [“Vinay”,”Sonia”,”Depak”]
names.insert(0,”Kim”)
print(names)
----------output----------
‘Kim’ ‘Vinay’ ‘Sonia’ ‘Deepak’
0 1 2 3
‘Vinay’ ‘Sonia’ ‘Deepak’
0 1 2
‘Vinay’ ‘Sonia’ ‘Deepak’‘Kim’
1 2 30
Extend
adds one list at the end of another list
Syntax: list_name.extend(list2_name)
list_name: It is the primary list, which will be extended
list2_name: It is the list which will added to list_name
Example: no1= [10, 20, 30]
no2= [15, 25, 35]
no1.extend (no2)
print (no1)
---------output---------- 10 20 30 15 25 35
10 20 30
15 25 35
10 20 30 15 25 35
Always towards the right side only
In this case no1 extended and concatenate list no2 with no1
to add to something in order to make it bigger or longer
So What is the difference between append() and extend()?
For Example: If we want to add 70,80,90 numbers in a list no.
no= [10, 20, 30]
0 1 2
10 20 30
Using : Append() method.
no.append(70) 0 1 2
10 20 30
3
70
no.append(80)
no.append(90)
0 1 2 3
10 20 30 70
4
80
0 1 2 3 4
10 20 30 70 80
5
90
print(no)
----------output---------- [10, 20, 30, 70, 80, 90]
So What is the difference between append() and extend()?
For Example: If we want to add 70,80,90 numbers in a list no.
no= [10, 20, 30]
0 1 2
10 20 30
Using : extend() method.
no.extend( ) 0 1 2
10 20 30
3 4 5
70 80 90
print(no)
----------output----------
[10, 20, 30, 70, 80, 90]
[70,80,90]
Index The index() function or method returns the index of first
matched item from the list. It returns the first occurrence
of an item for which the index position is to be searched
for in the list.
Syntax: list_name.index(item)
Example:
no= [10, 20, 30,40,50,60]
print (no.index(40))
---------output----------
3
10 20 30 40 50 60
0 1 2 3 4 5
Example:
no= [10, 20, 30,40,50,60]
k=no.index(40)
---------output----------
3
10 20 30 40 50 60
0 1 2 3 4 5
print (k)
3k=
Index
Example:
days=[“MON”, “TUE”, “WED”, “THU”, “FRI”, “SAT”, “SUN”]
print(days.index(‘TUE’))
---------output----------
1
MON TUE WED THU FRI SAT SUN
0 1 2 3 4 5 6
Sort This function sort() the items of the list, by default in
ascending or descending order.
Syntax: list_name.sort()
Example:
no= [40,10,50,20,60,30]
no.sort()
---------output----------
40 10 50 20 60 30
0 1 2 3 4 5
10 20 30 40 50 60
0 1 2 3 4 5print (no)
clear
Example:
days=[“MON”, “TUE”, “WED”, “THU”, “FRI”, “SAT”, “SUN”]
days.clear()
---------output----------
It is Empty list nothing display
MON TUE WED THU FRI SAT SUN
0 1 2 3 4 5 6
The clear() method removes all items from the list.
count
Example:
days=["player","games","player","player","example"]
print(days.count(“player”))
---------output----------
3
player games player player example
0 1 2 3 4
The count() method count how many times that item or value
found in a list.
print(k)
---------output----------
3
k=days.count(“player”)
OR
count
Example:
no=[5,15,5,20,35,6,9,17,5,8,5]
print(no.count(5))
---------output----------
4
5 15 5 20 35 6 9 17 5 8 5
0 1 2 3 4 5 6 7 8 9 10
The count() method count how many times that item or value
found in a list.
print(k)
---------output----------
4
k=no.count(5)
OR
Deletion operation
Python provide operators for deleting or removing an item from a list.
There are three method for deleting items from a list:-
If index is known, we can use pop() or del() method.
If the element is known, not the index value remove() method can be
used. It is used to delete items from the list using item or value
inside the list.
To remove more than one element, del() method is used with the
help of slice.
pop() del() remove()
pop() It removes the element from the specified index, and also
returns the element which was removed.
Syntax: list_name.pop()
Example:
no= [1,2,4,5,6,8,9,10,12,15,18]
0 1 2 3 4 5 6 7 8 9 10
print(no.pop(4))
---------output----------
6
print(no) [1,2,4,5,8,9,10,12,15,18]
Here the element deleted will be returned to print to display
pop() We can also store the deleted item inside another variable
also.
Syntax: list_name.pop()
Example:
no= [1,2,4,5,6,8,9,10,12,15,18]
0 1 2 3 4 5 6 7 8 9 10
k=no.pop(2)
---------output----------
4
print(k)
Here the element deleted will be returned to variable k
del() It removes the element from the specified index or using slicing ,
but does not returns the element which was removed.
Syntax: del listname[indexno]
Example:
no= [1,2,4,5,6,8,9,10,12,15,18]
0 1 2 3 4 5 6 7 8 9 10
del no[4]
---------output----------print(no)
[1,2,4,5,8,9,10,12,15,18]
del listname[start:end]OR
Index number Use of slicing method
del() It removes the element from the list using slicing.
For Example: If we delete values from index no. 4 to 8.
Syntax:
Example:
no= [1,2,4,5,6,8,9,10,12,15,18]
0 1 2 3 4 5 6 7 8 9 10
del no[ : ]
---------output----------print(no)
[1,2,4,5,15,18]
del listname[start:end]
Use of slicing method
4 9 9 means end value -1
remove() This function is used when we know the element number
not the index value.
Syntax: Listname.remove(item or value)
Example:
no= [1,2,4,5,6,8,9,10,12,15,18]
0 1 2 3 4 5 6 7 8 9 10
no.remove(12)
---------output----------
print(no)
[1,2,4,5,8,9,10,15,18]
It will delete the item 12 from the list no
max() It returns the element value with the maximum value
from the list.
Example:
no= [41,12,40,25,36,18,39,10,42,35,28]
0 1 2 3 4 5 6 7 8 9 10
print(max(no))
---------output----------42
print(min(no))
min() It returns the element value with the minimum value
from the list.
10
reverse() It reverse the order of elements in a list.
Example:
no= [15,16,17,18,19]
0 1 2 3 4
no.reverse()
---------output----------print(no)
[19,18,17,16,15]

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
 
The Ring programming language version 1.7 book - Part 26 of 196
The Ring programming language version 1.7 book - Part 26 of 196The Ring programming language version 1.7 book - Part 26 of 196
The Ring programming language version 1.7 book - Part 26 of 196Mahmoud Samir Fayed
 
Python tuples and Dictionary
Python   tuples and DictionaryPython   tuples and Dictionary
Python tuples and DictionaryAswini Dharmaraj
 
Arrays in python
Arrays in pythonArrays in python
Arrays in pythonLifna C.S
 
Python3 cheatsheet
Python3 cheatsheetPython3 cheatsheet
Python3 cheatsheetGil Cohen
 
Basic data structures in python
Basic data structures in pythonBasic data structures in python
Basic data structures in pythonLifna C.S
 
Python matplotlib cheat_sheet
Python matplotlib cheat_sheetPython matplotlib cheat_sheet
Python matplotlib cheat_sheetNishant Upadhyay
 
The Ring programming language version 1.3 book - Part 13 of 88
The Ring programming language version 1.3 book - Part 13 of 88The Ring programming language version 1.3 book - Part 13 of 88
The Ring programming language version 1.3 book - Part 13 of 88Mahmoud Samir Fayed
 
Basic R Data Manipulation
Basic R Data ManipulationBasic R Data Manipulation
Basic R Data ManipulationChu An
 
Pandas pythonfordatascience
Pandas pythonfordatasciencePandas pythonfordatascience
Pandas pythonfordatascienceNishant Upadhyay
 
Python For Data Science Cheat Sheet
Python For Data Science Cheat SheetPython For Data Science Cheat Sheet
Python For Data Science Cheat SheetKarlijn Willems
 
Math - Operations on Functions, Kinds of Functions
Math - Operations on Functions, Kinds of FunctionsMath - Operations on Functions, Kinds of Functions
Math - Operations on Functions, Kinds of FunctionsChuckie Balbuena
 

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
 
LIST IN PYTHON PART-2
LIST IN PYTHON PART-2LIST IN PYTHON PART-2
LIST IN PYTHON PART-2
 
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
 
The Ring programming language version 1.7 book - Part 26 of 196
The Ring programming language version 1.7 book - Part 26 of 196The Ring programming language version 1.7 book - Part 26 of 196
The Ring programming language version 1.7 book - Part 26 of 196
 
Python tuples and Dictionary
Python   tuples and DictionaryPython   tuples and Dictionary
Python tuples and Dictionary
 
Lists
ListsLists
Lists
 
Arrays in python
Arrays in pythonArrays in python
Arrays in python
 
Python Programming Essentials - M12 - Lists
Python Programming Essentials - M12 - ListsPython Programming Essentials - M12 - Lists
Python Programming Essentials - M12 - Lists
 
Python programming : Standard Input and Output
Python programming : Standard Input and OutputPython programming : Standard Input and Output
Python programming : Standard Input and Output
 
Python3 cheatsheet
Python3 cheatsheetPython3 cheatsheet
Python3 cheatsheet
 
Numpy python cheat_sheet
Numpy python cheat_sheetNumpy python cheat_sheet
Numpy python cheat_sheet
 
Basic data structures in python
Basic data structures in pythonBasic data structures in python
Basic data structures in python
 
Python matplotlib cheat_sheet
Python matplotlib cheat_sheetPython matplotlib cheat_sheet
Python matplotlib cheat_sheet
 
Python lists & sets
Python lists & setsPython lists & sets
Python lists & sets
 
Haskell 101
Haskell 101Haskell 101
Haskell 101
 
The Ring programming language version 1.3 book - Part 13 of 88
The Ring programming language version 1.3 book - Part 13 of 88The Ring programming language version 1.3 book - Part 13 of 88
The Ring programming language version 1.3 book - Part 13 of 88
 
Basic R Data Manipulation
Basic R Data ManipulationBasic R Data Manipulation
Basic R Data Manipulation
 
Pandas pythonfordatascience
Pandas pythonfordatasciencePandas pythonfordatascience
Pandas pythonfordatascience
 
Python For Data Science Cheat Sheet
Python For Data Science Cheat SheetPython For Data Science Cheat Sheet
Python For Data Science Cheat Sheet
 
Math - Operations on Functions, Kinds of Functions
Math - Operations on Functions, Kinds of FunctionsMath - Operations on Functions, Kinds of Functions
Math - Operations on Functions, Kinds of Functions
 

Similar to LIST IN PYTHON-PART 3[BUILT IN PYTHON]

python_avw - Unit-03.pdf
python_avw - Unit-03.pdfpython_avw - Unit-03.pdf
python_avw - Unit-03.pdfAshaWankar1
 
The Ring programming language version 1.5.2 book - Part 22 of 181
The Ring programming language version 1.5.2 book - Part 22 of 181The Ring programming language version 1.5.2 book - Part 22 of 181
The Ring programming language version 1.5.2 book - Part 22 of 181Mahmoud Samir Fayed
 
‏‏chap6 list tuples.pptx
‏‏chap6 list tuples.pptx‏‏chap6 list tuples.pptx
‏‏chap6 list tuples.pptxRamiHarrathi1
 
The Ring programming language version 1.10 book - Part 43 of 212
The Ring programming language version 1.10 book - Part 43 of 212The Ring programming language version 1.10 book - Part 43 of 212
The Ring programming language version 1.10 book - Part 43 of 212Mahmoud Samir Fayed
 
Unit 4 python -list methods
Unit 4   python -list methodsUnit 4   python -list methods
Unit 4 python -list methodsnarmadhakin
 
List_tuple_dictionary.pptx
List_tuple_dictionary.pptxList_tuple_dictionary.pptx
List_tuple_dictionary.pptxChandanVatsa2
 
Python programming workshop session 3
Python programming workshop session 3Python programming workshop session 3
Python programming workshop session 3Abdul Haseeb
 
The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.2 book - Part 12 of 84The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.2 book - Part 12 of 84Mahmoud Samir Fayed
 
The Ring programming language version 1.4 book - Part 6 of 30
The Ring programming language version 1.4 book - Part 6 of 30The Ring programming language version 1.4 book - Part 6 of 30
The Ring programming language version 1.4 book - Part 6 of 30Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 37 of 196
The Ring programming language version 1.7 book - Part 37 of 196The Ring programming language version 1.7 book - Part 37 of 196
The Ring programming language version 1.7 book - Part 37 of 196Mahmoud Samir Fayed
 
Python Programming: Lists, Modules, Exceptions
Python Programming: Lists, Modules, ExceptionsPython Programming: Lists, Modules, Exceptions
Python Programming: Lists, Modules, ExceptionsSreedhar Chowdam
 
Python Data Types.pdf
Python Data Types.pdfPython Data Types.pdf
Python Data Types.pdfNehaSpillai1
 

Similar to LIST IN PYTHON-PART 3[BUILT IN PYTHON] (20)

python_avw - Unit-03.pdf
python_avw - Unit-03.pdfpython_avw - Unit-03.pdf
python_avw - Unit-03.pdf
 
PYTHON.pptx
PYTHON.pptxPYTHON.pptx
PYTHON.pptx
 
07012023.pptx
07012023.pptx07012023.pptx
07012023.pptx
 
The Ring programming language version 1.5.2 book - Part 22 of 181
The Ring programming language version 1.5.2 book - Part 22 of 181The Ring programming language version 1.5.2 book - Part 22 of 181
The Ring programming language version 1.5.2 book - Part 22 of 181
 
Python lists
Python listsPython lists
Python lists
 
Python list
Python listPython list
Python list
 
‏‏chap6 list tuples.pptx
‏‏chap6 list tuples.pptx‏‏chap6 list tuples.pptx
‏‏chap6 list tuples.pptx
 
The Ring programming language version 1.10 book - Part 43 of 212
The Ring programming language version 1.10 book - Part 43 of 212The Ring programming language version 1.10 book - Part 43 of 212
The Ring programming language version 1.10 book - Part 43 of 212
 
Unit 4 python -list methods
Unit 4   python -list methodsUnit 4   python -list methods
Unit 4 python -list methods
 
Python data handling notes
Python data handling notesPython data handling notes
Python data handling notes
 
Chapter 15 Lists
Chapter 15 ListsChapter 15 Lists
Chapter 15 Lists
 
List_tuple_dictionary.pptx
List_tuple_dictionary.pptxList_tuple_dictionary.pptx
List_tuple_dictionary.pptx
 
Python programming workshop session 3
Python programming workshop session 3Python programming workshop session 3
Python programming workshop session 3
 
The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.2 book - Part 12 of 84The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.2 book - Part 12 of 84
 
The Ring programming language version 1.4 book - Part 6 of 30
The Ring programming language version 1.4 book - Part 6 of 30The Ring programming language version 1.4 book - Part 6 of 30
The Ring programming language version 1.4 book - Part 6 of 30
 
Python programming : List and tuples
Python programming : List and tuplesPython programming : List and tuples
Python programming : List and tuples
 
The Ring programming language version 1.7 book - Part 37 of 196
The Ring programming language version 1.7 book - Part 37 of 196The Ring programming language version 1.7 book - Part 37 of 196
The Ring programming language version 1.7 book - Part 37 of 196
 
Python for Beginners(v3)
Python for Beginners(v3)Python for Beginners(v3)
Python for Beginners(v3)
 
Python Programming: Lists, Modules, Exceptions
Python Programming: Lists, Modules, ExceptionsPython Programming: Lists, Modules, Exceptions
Python Programming: Lists, Modules, Exceptions
 
Python Data Types.pdf
Python Data Types.pdfPython Data Types.pdf
Python Data Types.pdf
 

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

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
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
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
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
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 

Recently uploaded (20)

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
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
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
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
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.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
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 

LIST IN PYTHON-PART 3[BUILT IN PYTHON]

  • 1. LIST IN PYTHON COMPUTER SCIENCE(083) XII PART - 3
  • 2. What is Built-in functions? Built-in functions that predefined and supplied along with the compiler are known as built-in functions. Inbuilt are those function which already in the library and we did not need to create our own. Let us discuss the built in functions of list
  • 4. Append It adds a single item to the end of the list list_name.append( item or value)Syntax: Example: if we declare and initialize the list with numbers as shown below: 10 20 30 40 no=[10,20,30,40] no.append(50) print(no) ------------output----------- 10 20 30 40 50 0 1 2 3 0 1 2 3 4 The new element added at the end (Right side) 50 4
  • 5. Insert It can be used to insert an element or object at a specified index. This function takes two arguments: the index where an item or object is to be inserted and the item or element itself. list_name.insert(index_no , value) Syntax: index_no : is the index where the new value is to be inserted value: is the new value to be inserted in the list
  • 6. Insert Example: If there are list in a python program no and numbers are 10, 20, 30 and we want to new number 25 between 20 and 30 in a list no. no= [10, 20, 30] no.insert (2,25) print(no) ----------output---------- 0 1 2 10 20 30 10 20 25 30 0 1 2 3 0 1 10 20 2 25 2 30 3
  • 7. Insert Example2: If there are list in a python program names , names in a list are “Vinay”, “Sonia”, “Deepak” and we want to new name “Kim” before “Vinay” in a list name names= [“Vinay”,”Sonia”,”Depak”] names.insert(0,”Kim”) print(names) ----------output---------- ‘Kim’ ‘Vinay’ ‘Sonia’ ‘Deepak’ 0 1 2 3 ‘Vinay’ ‘Sonia’ ‘Deepak’ 0 1 2 ‘Vinay’ ‘Sonia’ ‘Deepak’‘Kim’ 1 2 30
  • 8. Extend adds one list at the end of another list Syntax: list_name.extend(list2_name) list_name: It is the primary list, which will be extended list2_name: It is the list which will added to list_name Example: no1= [10, 20, 30] no2= [15, 25, 35] no1.extend (no2) print (no1) ---------output---------- 10 20 30 15 25 35 10 20 30 15 25 35 10 20 30 15 25 35 Always towards the right side only In this case no1 extended and concatenate list no2 with no1 to add to something in order to make it bigger or longer
  • 9. So What is the difference between append() and extend()? For Example: If we want to add 70,80,90 numbers in a list no. no= [10, 20, 30] 0 1 2 10 20 30 Using : Append() method. no.append(70) 0 1 2 10 20 30 3 70 no.append(80) no.append(90) 0 1 2 3 10 20 30 70 4 80 0 1 2 3 4 10 20 30 70 80 5 90 print(no) ----------output---------- [10, 20, 30, 70, 80, 90]
  • 10. So What is the difference between append() and extend()? For Example: If we want to add 70,80,90 numbers in a list no. no= [10, 20, 30] 0 1 2 10 20 30 Using : extend() method. no.extend( ) 0 1 2 10 20 30 3 4 5 70 80 90 print(no) ----------output---------- [10, 20, 30, 70, 80, 90] [70,80,90]
  • 11. Index The index() function or method returns the index of first matched item from the list. It returns the first occurrence of an item for which the index position is to be searched for in the list. Syntax: list_name.index(item) Example: no= [10, 20, 30,40,50,60] print (no.index(40)) ---------output---------- 3 10 20 30 40 50 60 0 1 2 3 4 5
  • 12. Example: no= [10, 20, 30,40,50,60] k=no.index(40) ---------output---------- 3 10 20 30 40 50 60 0 1 2 3 4 5 print (k) 3k=
  • 13. Index Example: days=[“MON”, “TUE”, “WED”, “THU”, “FRI”, “SAT”, “SUN”] print(days.index(‘TUE’)) ---------output---------- 1 MON TUE WED THU FRI SAT SUN 0 1 2 3 4 5 6
  • 14. Sort This function sort() the items of the list, by default in ascending or descending order. Syntax: list_name.sort() Example: no= [40,10,50,20,60,30] no.sort() ---------output---------- 40 10 50 20 60 30 0 1 2 3 4 5 10 20 30 40 50 60 0 1 2 3 4 5print (no)
  • 15. clear Example: days=[“MON”, “TUE”, “WED”, “THU”, “FRI”, “SAT”, “SUN”] days.clear() ---------output---------- It is Empty list nothing display MON TUE WED THU FRI SAT SUN 0 1 2 3 4 5 6 The clear() method removes all items from the list.
  • 16. count Example: days=["player","games","player","player","example"] print(days.count(“player”)) ---------output---------- 3 player games player player example 0 1 2 3 4 The count() method count how many times that item or value found in a list. print(k) ---------output---------- 3 k=days.count(“player”) OR
  • 17. count Example: no=[5,15,5,20,35,6,9,17,5,8,5] print(no.count(5)) ---------output---------- 4 5 15 5 20 35 6 9 17 5 8 5 0 1 2 3 4 5 6 7 8 9 10 The count() method count how many times that item or value found in a list. print(k) ---------output---------- 4 k=no.count(5) OR
  • 18. Deletion operation Python provide operators for deleting or removing an item from a list. There are three method for deleting items from a list:- If index is known, we can use pop() or del() method. If the element is known, not the index value remove() method can be used. It is used to delete items from the list using item or value inside the list. To remove more than one element, del() method is used with the help of slice. pop() del() remove()
  • 19. pop() It removes the element from the specified index, and also returns the element which was removed. Syntax: list_name.pop() Example: no= [1,2,4,5,6,8,9,10,12,15,18] 0 1 2 3 4 5 6 7 8 9 10 print(no.pop(4)) ---------output---------- 6 print(no) [1,2,4,5,8,9,10,12,15,18] Here the element deleted will be returned to print to display
  • 20. pop() We can also store the deleted item inside another variable also. Syntax: list_name.pop() Example: no= [1,2,4,5,6,8,9,10,12,15,18] 0 1 2 3 4 5 6 7 8 9 10 k=no.pop(2) ---------output---------- 4 print(k) Here the element deleted will be returned to variable k
  • 21. del() It removes the element from the specified index or using slicing , but does not returns the element which was removed. Syntax: del listname[indexno] Example: no= [1,2,4,5,6,8,9,10,12,15,18] 0 1 2 3 4 5 6 7 8 9 10 del no[4] ---------output----------print(no) [1,2,4,5,8,9,10,12,15,18] del listname[start:end]OR Index number Use of slicing method
  • 22. del() It removes the element from the list using slicing. For Example: If we delete values from index no. 4 to 8. Syntax: Example: no= [1,2,4,5,6,8,9,10,12,15,18] 0 1 2 3 4 5 6 7 8 9 10 del no[ : ] ---------output----------print(no) [1,2,4,5,15,18] del listname[start:end] Use of slicing method 4 9 9 means end value -1
  • 23. remove() This function is used when we know the element number not the index value. Syntax: Listname.remove(item or value) Example: no= [1,2,4,5,6,8,9,10,12,15,18] 0 1 2 3 4 5 6 7 8 9 10 no.remove(12) ---------output---------- print(no) [1,2,4,5,8,9,10,15,18] It will delete the item 12 from the list no
  • 24. max() It returns the element value with the maximum value from the list. Example: no= [41,12,40,25,36,18,39,10,42,35,28] 0 1 2 3 4 5 6 7 8 9 10 print(max(no)) ---------output----------42 print(min(no)) min() It returns the element value with the minimum value from the list. 10
  • 25. reverse() It reverse the order of elements in a list. Example: no= [15,16,17,18,19] 0 1 2 3 4 no.reverse() ---------output----------print(no) [19,18,17,16,15]