#python #dataStructures #U3-AOS1
In Python, a list is a collection of items that are ordered and mutable (you can add or remove items after creating the list). You can think of a list as a container that holds multiple values, such as numbers, strings, or even other lists.
***It's important to note that a list is NOT an array (in terms of VCAA)
VCAA defines 1D arrays as single data type and integer index
This is important for the exam as questions discussing a one-dimensional array is NOT referring to a list.
One of the main purposes of using a list in Python is to store and organize data in a way that makes it easy to access and manipulate. For example, if you have a list of numbers, you can use Python's built-in functions to sort, filter, or perform mathematical operations on those numbers.
Here's a simple example of how you might create a list in Python:
```python
grocery_list = ["Apples", "Milk", "Pasta", "Bread", "Eggs"]
```
Once you have a list, you can access individual items by their index (i.e., their position in the list). In Python, the first item in a list is always at index 0.
| Index | 0 | 1 | 2 | 3 | 4 |
| --------- | -------- | ------ | ------- | ------- | ------ |
| **Value** | "Apples" | "Milk" | "Pasta" | "Bread" | "Eggs" |
Here's an example of how you might access the first item in the numbers list:
```python
print(grocery_list[0])
```
![[ArrayVisualization 1.mp4]]
You can also add new items to a list, remove existing items, or modify the values of existing items. Here are a few examples:
```python
#add a new number from the list
data.append(6)
#Remove the third nunmber from the list
del data[2]
#Change the value of the second item in the list
data[1] = 10
```
Finally, it's worth noting that lists can be very powerful when combined with other programming concepts like loops and conditionals. For example, you might use a loop to iterate through each item in a list and perform some action on each item, or use a conditional to filter out certain items based on some criteria.
### How to use lists
![[Pasted image 20251118130044.jpeg]]
![[Pasted image 20251118130109.png]]