List Manipulation 4

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 8

LIST

MANIPULATION 4
LIST FUNCTIONS AND METHODS

The len() function

Returns the length of its argument list. i.e it returns the number
of elements in the passed list. It is Python’s standard library
function.
The list() method

Returns a list created from the passed argument, which should


be a sequence type (string, list or tuple)
The index() method

This function returns the index of first matched item from the
list.
If the given item is not in the list, it raises ValueError.
The append() method

This method adds an item to the end of the list. It modifies the
original list.
The extend() method

This method is used to add multiple elements to a list. The new


elements should be given in the form of a list.
The difference between append() and extend() methods

The append() method can add a single element to the end of a


list while extend() can add argument list’s all elements to the
end of the list.

After append() the length of the list increases by 1 and after


extend() the length of the list will be increased by the length of
inserted list.
The insert() method

This method is also an insertion method for lists. It inserts an


element somewhere in between or any position of the given list.

In the above example of insert() method, 2 is the index value


where the given string is to be inserted

You might also like