Lists
The simplest way to structure data is a list, which allows users to access and store sequences of items.
Notice here how each data structure has to adhere to certain conventions:
[“apple”, “orange”, “banana”]
A list structure is defined by the use of square brackets ([]) and commas to separate individual objects within it.
Zero-Based Indexing
So what if you have a list of objects, but only need to access one?
fruit = [“apple”, “orange”, “banana”, “grapes”, “melon”, “pineapple”]
The above example contains a list of fruit, each item on the list has a value (fruit name) and an index (its position in the list).
That means the first element (value “orange”) has an index 1.
Notice how we said 1 there and not 2?
In Python we start at 0, rather than 1, which is often called zero based indexing.
To access an element by its index, you need to use square brackets – like the example below.
fruit[0]