Lists

Lists can contain any type of variables and can contain as many variables as you would like. Lists can be iterated as much as you want and is very simple to do.

To start a list you must use square brackets when making the variable like so:

List = []

To add to the list you can use the append function like so:

List.append(10)

List.append(20)

Or you could just place the numbers in the list beforehand like so:

List = [10, 20, 30]

You can print certain IDs from a list at any point, starting from 0.

If there is 3 items in a list and you use the command

print(List[0])

It will print the first variable in the list.

Ensure you only print the ID of the variables you have in the list and no more otherwise it will error out.

Continue to the next lesson