0% found this document useful (0 votes)
15 views1 page

List Methods

The document lists various methods and functions applicable to Python lists, providing syntax, examples, and expected outputs. Key methods include 'len', 'append', 'pop', 'remove', 'clear', and 'sort', among others. Each method is illustrated with an example and its resulting output for clarity.

Uploaded by

afbbscomplab
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)
15 views1 page

List Methods

The document lists various methods and functions applicable to Python lists, providing syntax, examples, and expected outputs. Key methods include 'len', 'append', 'pop', 'remove', 'clear', and 'sort', among others. Each method is illustrated with an example and its resulting output for clarity.

Uploaded by

afbbscomplab
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
You are on page 1/ 1

LIST METHODS

SYNTAX:<list object>.<method name>()


L1=[1,2,3,4,5]
S NO ,METHOD/FUNCTION EG OUTPUT
1 LEN len(l1) 5
2 ist list(“hello”) [“h”,”e”,”l”,”l”,”o”]
3 index l1 index(3) 2
4 append l1.append(3) [1,2,3,4,5,3]
5 extend l1.extend([5,6,7]) l1=[1,2,3,4,5,3,5,6,7]
6 insert insert(<index>,<value>)
Insert(5,10) l1=[1,2,3,4,5,10,3,5,6,7]
7 pop <list>.pop(<index>)
P=l1.pop(6) p=3 (list element is delted)

8 remove <list>remove(<value>)
L1.remove(10) l1=[1,2,3,4,5,3,5,6,7]

9 clear l1.clear() l1=[]

10 count l1.count(5) 2
11 reverse l1.reverse() l1=[7,6,5,4,3,2,1]
12 sort(sorts the list(in ascending)) l1.sort() l1=[1,2,3,4,5,6,7]
(for descending reverse)

13 sorted() l2=l1.sorted()
14 max() l1.max(l1) 7
15 min() l1.min(l1) 1
16 sum() l1.sum(l1) 28

You might also like