Sign In for Full Access

Quick access through the institutional single sign-on Manchester Met Sign In
Skip this for now
|
Public Access Here

Sign In for Free Access

Login with email for free guest access to a range of Rise content
Go!
Logging You In!
Incorrect Password (Click Here to Reset)! Passwords Must Match Password must be more than 8 characters
Skip this for now
|
Man Met Access Here
menu

Structuring Data

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]