A list is a data structure in python which can be used as a more general version of the sequence. Unlike strings lists are mutable, means the elements inside a string can be changed.

A list is constructed with brackets [ ] and commas (,) separating every element in the list.

Let’s see some list operations in python.

List methods in Python

How to create, assign and find the length of a list?

Show Output

How to create, add, grab, append, pop, remove items in the list?

Show Output

Basic List Methods

  • sort() – Sort the values of the list in ascending order.
  • count(x) – Count the frequency of ‘x’ in the list.
  • append(x) – Add ‘x’ to the list.
  • pop() – Remove last element from the list.
  • reverse() – Reverses the list.
  • index(x) – Returns the index of element ‘x’.
  • remove(x) – Removes first appearance of ‘x’ from the list.
  • clear() – Removes all elements from the list.

Leave a Reply

Close Menu