Python Lists and List Methods

Python 9 min min read Updated: Mar 09, 2026 Intermediate
Python Lists and List Methods
Intermediate Topic 2 of 10

Lists & List Methods in Python

Lists are one of the most commonly used data structures in Python. A list allows you to store multiple items in a single variable. These items can be of different data types such as numbers, strings, or even other lists.

Lists are very flexible and powerful because they are ordered, changeable, and allow duplicate values. Python provides many built-in methods that make it easy to work with lists efficiently.

What is a List in Python?

A list is a collection of items stored in a specific order. Lists are created using square brackets [] and elements are separated by commas.

python fruits = ["apple", "banana", "mango"] print(fruits)

In this example, the variable fruits contains three items stored in a list.

Accessing List Elements

List elements can be accessed using their index position. In Python, indexing starts from 0.

python fruits = ["apple", "banana", "mango"] print(fruits[0]) print(fruits[1])

The first element in the list has index 0, the second has index 1, and so on.

Negative Indexing

Python also supports negative indexing, which allows access to elements from the end of the list.

python numbers = [10, 20, 30, 40] print(numbers[-1])

This will print the last element of the list.

Changing List Elements

Since lists are mutable, you can modify their elements.

python fruits = ["apple", "banana", "mango"] fruits[1] = "orange" print(fruits)

The value at index 1 is replaced with "orange".

Adding Elements to a List

Python provides multiple methods to add elements to a list.

Using append()

The append() method adds an item to the end of the list.

python numbers = [1, 2, 3] numbers.append(4) print(numbers)

Using insert()

The insert() method adds an element at a specific position.

python numbers = [1, 2, 3] numbers.insert(1, 10) print(numbers)

Removing Elements from a List

Python also provides methods to remove elements from a list.

Using remove()

python fruits = ["apple", "banana", "mango"] fruits.remove("banana") print(fruits)

Using pop()

The pop() method removes an element based on its index.

python numbers = [10, 20, 30] numbers.pop(1) print(numbers)

Using clear()

The clear() method removes all elements from the list.

python numbers = [1, 2, 3] numbers.clear() print(numbers)

Common List Methods

Method Description
append() Adds an element to the end of the list
insert() Inserts an element at a specified position
remove() Removes the specified item
pop() Removes element at a specific index
clear() Removes all elements
index() Returns the index of a specific value
count() Counts occurrences of a value
sort() Sorts the list
reverse() Reverses the order of elements

Sorting a List

The sort() method arranges elements in ascending order.

python numbers = [5, 2, 9, 1] numbers.sort() print(numbers)

Reversing a List

The reverse() method reverses the order of elements.

python numbers = [1, 2, 3, 4] numbers.reverse() print(numbers)

Looping Through a List

You can iterate through a list using a loop.

python fruits = ["apple", "banana", "mango"] for fruit in fruits: print(fruit)

List Length

The len() function returns the number of items in a list.

python numbers = [10, 20, 30] print(len(numbers))

Real-World Example

Lists are commonly used to store collections of data such as student names or product prices.

python students = ["Rahul", "Amit", "Priya"] students.append("Neha") for student in students: print(student)

Best Practices for Using Lists

  • Use lists when working with ordered collections.
  • Use meaningful variable names for lists.
  • Use list methods instead of writing complex logic.
  • Avoid modifying lists while iterating unless necessary.

Conclusion

Lists are one of the most powerful and flexible data structures in Python. They allow developers to store, organize, and manipulate collections of data efficiently.

By understanding list operations and built-in list methods, programmers can build more dynamic and efficient Python applications.

In the next tutorial, we will explore Tuples & Tuple Operations in Python and learn how tuples differ from lists.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators