7 Lists


A list is a collection that is ordered and has changeable content.

There are other data[7] collection methods in python[8] such as:

  • List is a collection which is ordered and changeable. Allows duplicate members.
  • Tuple is a collection which is ordered and unchangeable. Allows duplicate members.
  • Set is a collection which is unordered and unindexed. No duplicate members.
  • Dictionary is a collection which is unordered, changeable and indexed. No duplicate members.

Find out more about them on the W3 schools site

You might hear about arrays in other programming[1] languages. Python[8] doesn’t support[2] Arrays, lists are the closest that Python has to them.

Lists are pieces of data that can be identified with [ ]

fruit = ["apple", "banana", "chicken", 293, "durian"]

This list above has five items.

Lists in Python can have multiple types of data stored inside them. It’s good practice to keep the data in a list to one data type[3] where possible.

Each item has a position.

In programming we start counting at 0, so the first position is position 0. These positions are known as indexes.

fruit[0] would get the first item in the list “apple”

Note that typing just the variable[4] name of the list will print out the entire contents of the list. This is useful for checking the contents of a list when testing[5] or initially writing a program.

fruit[0] will get just the data at that index of the list.

We can also find the length of a list by using the len() function[6]

Inside the brackets () we put the content to find the length of

As shown in the code example above the number 5 is printed.

We can also remove items from the list

We use the del keyword to do this.

For more information check out the W3 Schools page on Python Lists

You can find more information on strings and manipulating them in Python here on W3 Schools

Terms definitions
1. programming. The process of writing a programme
2. support. When assistiance ir provided or given.
3. data type. The format that a piece of data is stored in. It is important as you should only manipulate data that is of the same type. Examples of data types are integer, float, boolean, character, string, date / time.
4. variable. A placeholder for a piece of information that can change.
5. testing. Testing is about confirming decisions and ensuring that the desired result is produced form and outcome or component.