Introduction to Wagtail | Coders of Colour
Lists
Lists in Python are variables in which we can put several variables.
We can declare them empty or with variables insdie them:
names = []colours = ['red', 'yellow', 'blue']post_codes = [75001, 75002, 75003]person = [3, 'Bob']
A list is also a variable. Once declared, we can use it in the rest of the program.
print(post_codes)
To access elements in a list, we can ask to see the index of the value we are looking for.
The first element of a list has index 0. In programming, we start counting from 0 and not from 1. If we are looking for the third element we will look for the element at index 2.
colours = ['red', 'yellow', 'blue']colours[0]colours[2]