> For the complete documentation index, see [llms.txt](https://www.pythonclassroom.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.pythonclassroom.com/lists.md).

# Lists

## Presentation

{% embed url="<https://docs.google.com/presentation/d/1Yi1-kP2mP4IrK0KBb0miyZtmfR_-cM0qRFv3FD5upBk/edit?usp=sharing>" %}

## Video Lecture

{% embed url="<https://youtu.be/oCj2tz9YJMQ>" %}

## List Functions and Operators

|                                      |                                                                                                                          |
| ------------------------------------ | ------------------------------------------------------------------------------------------------------------------------ |
| list\_name = \[]                     | Creates an empty list                                                                                                    |
| list\_name = \[1,2,3,4,5]            | A list with elements 1,2,3,4,5                                                                                           |
| list\_name\[0]                       | Access the first element of the list                                                                                     |
| list\_name\[x-1]                     | Access the *x* element of the list                                                                                       |
| len(list\_name)                      | Returns the number of elements in list.  Useful when using a for loop and the range function.                            |
| sum(list\_name)                      | Computes the sum of the values in list.                                                                                  |
| min(list\_name)                      | Returns the minimum value in list.                                                                                       |
| max(list\_name)                      | Returns the maximum value in list.                                                                                       |
| list\_name.pop()                     | Removes the last element from list.                                                                                      |
| list\_name.pop(position)             | Removes element from the list from the given position.  All elements following are moved up one place.                   |
| list\_name.insert(position, element) | Inserts the element at the given position in the list.  All elements at and following the given position are moved down. |
| list\_name.append(element)           | Appends the element to the end of the list.                                                                              |
| list\_name.index(element)            | Returns the position of a given element in the list.  The element must be in the list.                                   |
| list\_name.remove(element)           | Removes the given element from the list and moves all elements following it up one position.                             |
| list\_name.del(position)             | Removes the element from the list by the given position.                                                                 |
| list\_name.sort()                    | Sorts the elements in the list from smallest to largest.                                                                 |
| item in list\_name                   | Returns true if item is found in the list or false otherwise.                                                            |

### Loop through a list

```python
friends = ["Sam", "Taylor", "Sandy"]
# Pythonic Way
for f in friends:
    print(f)

# C Style
for i in range(len(friends)):
    print(friends[i])
```

####


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.pythonclassroom.com/lists.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
