0% found this document useful (0 votes)
18 views2 pages

Python List Functions Explained

The document provides a summary of various list functions in Python, including their descriptions and examples of usage. Functions such as Len(), List(), Append(), Extend(), Insert(), Count(), Index(), Remove(), Pop(), Reverse(), Sort(), Sorted(), Min(), Max(), and Sum() are detailed with their specific functionalities. Each function is accompanied by example code and expected output to illustrate its use.

Uploaded by

divyameher2004
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

Python List Functions Explained

The document provides a summary of various list functions in Python, including their descriptions and examples of usage. Functions such as Len(), List(), Append(), Extend(), Insert(), Count(), Index(), Remove(), Pop(), Reverse(), Sort(), Sorted(), Min(), Max(), and Sum() are detailed with their specific functionalities. Each function is accompanied by example code and expected output to illustrate its use.

Uploaded by

divyameher2004
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Functions Descriptions Example

Len() Returns the length of the list >list1=[10,20,30,40,50]


passed as argument >len(list1)
O.P>5
List() Creates an empty list if no >list1=list()
argument is passed. >list1
Creates a list if a sequence is O.P>[]
passed as an argument >Str1=’aeiou’
>List1=list(str1)
>list1
O.P>[‘a’,’e’,’I’,’o’,’u’]
Append() Appends a single element >list1=[10,20,30,40]
passed as an argument at the >[Link](50)
end of the list. The single >list1
element can also be a list O.P>[10,20,30,40,50]
>[Link]([10,20])
>list1
O.P>[10,20,30,40,50,[10,20]]
Extend() Appends each element of the >list1=[10,20,30]
list passed as argument to the >list2=[40,50]
end of the list >[Link](list2)
O.P>[10,20,30,40,50]
Insert() Inserts an elsement at a >list1=[10,20,30,40,50]
particular index in the list >[Link](2,25)
>list1
O.P>[10,20,25,30,40,50]

Count() Returns the number of times a >list1=[10,20,30,10,40,20,10]


given element appears in the >[Link](10)
list. O.P>3
>[Link](70)
O.P> 0
Index() Returns index of the first >list1=[10,20,30,20,40,10]
occurance of the element in >[Link](20)
the list. If the element is not O.p>1
present,Value Error is >[Link](90)
generated. O.P>Valueerror
Remove() Remoces the given element >list1=[10,20,30,40,50,30]
from the list. If the element is >[Link](30)
present multiple times, only O.P>[10,20,40,50,30]
the first occurance is >[Link](9)
removed. If the element is not O.P>valueerror
present,then valueerror is
generated
Pop() Returns the element whose >list1=[10,20,30,40,50,60]
index is passed as parameter >[Link](3)
to this function and also O.P>40
removes it from the list. If no >list1
parameter is given, then it O.P>[10,20,30,50,60]
returns and removes the lase >[Link]() -removes last
element of the list element
o.P>[10,20,30,50]
Reverse() Reverse the order of elements >List1=[[10,20,30,40,50]
in the given list >[Link]()
>list1
O.P>[50,40,30,20,10]
>list2=[‘a’,’e’,’I’,’o’.u’]
>[Link]()
O.P>{‘u’,’o’,’I’,’e’,’a’]
Sort() Sorts the elements of the >list1=[‘s’,’a’,’b’,’y’]
given list >[Link]()
>list1
O.P>[a,b,s,y]
>[Link](reverse=true)
O.P>[y,s,b,a]

Sorted It takes a list as parameter and >list1=[10,50,40,80,20]


creates a new list consisting of >[Link](list1)
the same elements arranged in >list1
sorted order O.P>[10,50,40,80,20]
>list2
O.P>[10,20,40,50,80]

Min() Returns the minimum or


smallest element of the list
Max() Returns maximum or largest
element of the list
Sum() Returns sum of the element of
the list

You might also like