0% found this document useful (0 votes)
16 views

5. Data Structures — Python 3.13.2 documentation

This document provides detailed information about the list data type in Python 3.13.2, including various methods such as append, extend, insert, remove, pop, clear, index, count, sort, and reverse. Each method is briefly described along with its functionality and usage. The chapter aims to enhance understanding of lists and their operations in Python.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

5. Data Structures — Python 3.13.2 documentation

This document provides detailed information about the list data type in Python 3.13.2, including various methods such as append, extend, insert, remove, pop, clear, index, count, sort, and reverse. Each method is briefly described along with its functionality and usage. The chapter aims to enhance understanding of lists and their operations in Python.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

2/19/25, 11:13 PM 5. Data Structures — Python 3.13.

2 documentation

5. Data Structures
This chapter describes some things you’ve learned about already in more detail, and adds some new things as
well.

5.1. More on Lists

The list data type has some more methods. Here are all of the methods of list objects:

list.append(x)
Add an item to the end of the list. Similar to a[len(a):] = [x] .

list.extend(iterable)
Extend the list by appending all the items from the iterable. Similar to a[len(a):] = iterable .

list.insert(i, x)
Insert an item at a given position. The first argument is the index of the element before which to insert, so
a.insert(0, x) inserts at the front of the list, and a.insert(len(a), x) is equivalent to a.append(x) .

list.remove(x)
Remove the first item from the list whose value is equal to x. It raises a ValueError if there is no such
item.

list.pop([i])
Remove the item at the given position in the list, and return it. If no index is specified, a.pop() removes
and returns the last item in the list. It raises an IndexError if the list is empty or the index is outside the
list range.

list.clear()
Remove all items from the list. Similar to del a[:] .

list.index(x[, start[, end]])


Return zero-based index in the list of the first item whose value is equal to x. Raises a ValueError if
there is no such item.

The optional arguments start and end are interpreted as in the slice notation and are used to limit the
search to a particular subsequence of the list. The returned index is computed relative to the beginning of
the full sequence rather than the start argument.

list.count(x)
Return the number of times x appears in the list.

list.sort(*, key=None, reverse=False)


Sort the items of the list in place (the arguments can be used for sort customization, see sorted() for
their explanation).

list.reverse()

https://docs.python.org/3/tutorial/datastructures.html#nested-list-comprehensions 1/11

You might also like