Python List Methods

The Python List is a general data structure widely used in Python programs.

They are both mutable and can be indexed and sliced.

List methods

1 – append(value)

Append a new element to the end of the list.

2 – extend(value)

Extends the list by appending elements from another enumerable.

3 – index(value)

Gets the index of the first occurrence of the input value. If the input value is not in the list a ValueError exception is raised.

4 – insert (index, value)

Inserts value just before the specifies index. Thus, after the insertion the new element occupies position index.

5 – pop([index])

Removes and returns the item at index. With no argument it removes and returns the last element of the list.

6 – remove (value)

Removes the list occurrence of the specified value. If the provided value cannot be found, a ValueError is raised.

7 – reverse()

Reverses the list in-place and return None.

8 – clear() – removes all items from the list

9 – count(value)

Counts the number of occurrences of some value in the list.

10 – sort() – sort the list

Popular Posts

Spread the knowledge

One thought on “Python List Methods

Leave a Reply

Your email address will not be published. Required fields are marked *