List: A list of multiple things, like variable but multiple things inside
List = [x, y, z]

Lists are mutable/changeable, so you can ex. Change an index of a list, by just writing
list[0] = x, then list index 0 will become x
And they can also be empty

Append(x): adds x into the list

Pop(x): removes x from the list

Extend(x): when x is a list it adds that list to the list the method is used on

In: can be used in if-statements like if there is a certain number or string in the list
If “lol” in list:

Average(): Gives you the average of the list in the parenthesis

Len(): gives you the length of the list

For loops can go through a list by saying:
For i in list:

Nested list: You can have a multiple lists in a list

Sorted(): sorts the list in the parenthesis to have the lowest number first or in alphabetical order
Can also use .sort()
If there are capital letters then will be sorted before the lowercase letters so ‘W’ comes before ‘g’, just because it’s uppercase
A way to get not to happen is to add ‘key=str.lower’ into the .sort() parenthesis

Min() and max(): gives you the minimum or maximum value of a list

Sum(): gives you the sum of all of the numbers in a list
When indexing lists, nested lists won’t count towards items in that list
[‘spam’, 1, [‘Brie’, ‘Roquefort’, ‘Pol le Veq’], [1, 2, 3]]
This list technically only has 4 items

No Responses

Leave a Reply

Your email address will not be published. Required fields are marked *