List Methods

Owosenikehinde
2 min readMay 21, 2021

--

A list is a data structure in Python that is a mutable(changeable), ordered sequence of elements. Lists are used to store multiple elements in a single variable.

We use square brackets [] to indicate the start and end of the list, and separate the items by commas(,).

With list method we are able to manipulate the elements in a list.

Here are a couple of List methods you might find useful.

Append()

This adds a single element to the end of a list.

Append takes one argument at a time.

Sort()

This arranges the list in ascending order.

From lowest to highest in value.

Count()

This returns the number of times an element occurs in the list.

Index()

This returns the location of the first occurrence of element in the list.

Reverse()

This reverses the order of a list.

Remove()

This removes the first occurrence of an element from a list

Conclusion

Methods come in handy when we need to manipulate the elements of a list. From sorting, getting the minimum and maximum values of a list, replacing elements name it. List methods are very useful in building sustainable code.

--

--

No responses yet