Oliver Irwin
10th March 2023
Say you are a teacher and you are grading students
You want to store the students’ grade in a variable
If you have one student, it’s easy!
What happens if you now have 2 students?
Imagine you now have 12 students
Seems complicated to handle…
We introduce a new type to handle sets of data
A list is a set of variables grouped into one
In Python, lists are created like variables
The data has to be enclosed by square brackets [
The elements have to be separated by commas ,
Every element in a list has an index
They start at 0
Item | mon | tue | wed | thu | fri | sat | sun |
---|---|---|---|---|---|---|---|
index | 0 |
1 |
2 |
3 |
4 |
5 |
6 |
To access an element in a list, you use it’s index
You can add elements to the end of a list
You can add two lists together