Skip to content

list

The built-in list data type is a versatile and widely-used data structure in Python that allows for the storage and manipulation of ordered, mutable sequences of elements.

Lists can contain heterogeneous data types and support a wide array of operations, making them essential for organizing and processing data in Python:

Language: Python
>>> colors = ["red", "green", "blue"]
>>> colors[0]
'red'

list Constructor

Language: Python Syntax
list(iterable=(), /)

Arguments

Argument Description
iterable Optional and positional-only. Any iterable object, such as a sequence, container, or iterator, to convert into a list. It defaults to an empty tuple, so list() returns [].

Return Value

  • Returns a Python list object

list Examples

Creating an empty instance:

Language: Python
>>> empty = []
>>> empty
[]

Creating instances using a literal:

Language: Python
>>> fruits = ["apple", "banana", "cherry"]
>>> fruits
['apple', 'banana', 'cherry']

Creating an instance using the class constructor:

Language: Python
>>> list((1, 2, 3))
[1, 2, 3]

Note that the example above uses a tuple as the argument.

Accessing values:

Language: Python
>>> fruits[1]
'banana'

Changing values:

Language: Python
>>> fruits[0] = "mango"
>>> fruits
['mango', 'banana', 'cherry']

Deleting values using the del keyword:

Language: Python
>>> del fruits[2]
>>> fruits
['mango', 'banana']

list Methods

Method Description
.append() Adds an element to the end of the list.
.extend() Extends the list by appending elements from an iterable.
.insert() Inserts an element at a specified position.
.remove() Removes the first occurrence of a value.
.pop() Removes and returns the element at the specified position.
.clear() Removes all elements from the list.
.index() Returns the index of the first occurrence of a value.
.count() Returns the number of occurrences of a value.
.sort() Sorts the list in place.
.reverse() Reverses the list in place.
.copy() Returns a shallow copy of the list.

list Common Use Cases

The most common use cases for list include:

  • Storing and organizing sequences of data
  • Iterating over elements for processing
  • Dynamically adding or removing elements
  • Accessing elements by index
  • Sorting and reversing collections

list Real-World Example

Consider a scenario where you need to manage a list of tasks in a to-do application. You can use a list to store the tasks, allowing users to add, remove, and prioritize tasks efficiently.

Language: Python
>>> tasks = []

>>> # Adding tasks
>>> tasks.append("Write report")
>>> tasks.append("Call John")

>>> # Prioritizing a task
>>> tasks.insert(0, "Pay bills")

>>> # Completing a task
>>> completed_task = tasks.pop(1)

>>> # Current list of tasks
>>> tasks
['Pay bills', 'Call John']

In this example, the list data type helps in managing and organizing tasks efficiently, allowing for easy addition, removal, and prioritization of tasks.

Python's list Data Type: A Deep Dive With Examples

Course

Exploring Python's list Data Type With Examples

In this video course, you'll dive deep into Python's lists: how to create them, update their content, populate and grow them - with practical code examples.

intermediate data-structures python

For additional information on related topics, take a look at the following resources:


By Leodanis Pozo Ramos • Updated Aug. 31, 2026 • Reviewed by Brenda Weleschuk and Dan Bader