TOPIC 5: Python Lists

Site: Learning Management System
Course: Edo College ICT Club Programme
Book: TOPIC 5: Python Lists
Printed by: Guest user
Date: Wednesday, 26 August 2026, 7:07 AM

1. Python Lists

Introduction

Lists are used to store multiple items in a single variable.

In Python, a List is one of the built-in data types used to store collections of data. Instead of creating multiple variables to store related information, we can store them together in a single list.

For example, instead of writing:

fruit1 = "apple"
fruit2 = "banana"
fruit3 = "cherry"

We can store all the values in a single list:

fruits = ["apple", "banana", "cherry"]

Lists are created using square brackets [].

Example:

thislist = ["apple", "banana", "cherry"]
print(thislist)

Output:

['apple', 'banana', 'cherry']

2. List Items & Ordered Lists

List Items

The values stored inside a list are called List Items.

thislist = ["apple", "banana", "cherry"]

In this example:

  • apple is a list item

  • banana is a list item

  • cherry is a list item

Ordered Lists

Lists are ordered.

This means that the items in a list have a defined position and order.

thislist = ["apple", "banana", "cherry"]

The order is:

  1. apple

  2. banana

  3. cherry

When a new item is added to the list, it is usually added to the end of the list.

3. Changeable Lists & Allow Duplicates

Changeable Lists

Lists are changeable.

This means that after creating a list, we can modify, add, or remove items from it.

Example:

thislist = ["apple", "banana", "cherry"]

thislist[1] = "orange"

print(thislist)

Output:
['apple', 'orange', 'cherry']

Allow Duplicates

Lists allow duplicate values.

This means that the same item can appear more than once in a list.

Example:

thislist = ["apple", "banana", "cherry", "apple", "cherry"]

print(thislist)

Output:
['apple', 'banana', 'cherry', 'apple', 'cherry']

4. List length, List Items & Data Types

List Length

To determine the number of items in a list, use the len() function.

Example:

thislist = ["apple", "banana", "cherry"]

print(len(thislist))

Output:
3

List Items and Data Types

List items can be of any data type.

String List

list1 = ["apple", "banana", "cherry"]

Integer List

list2 = [1, 5, 7, 9, 3]

Boolean List

list3 = [True, False, False]

5. Mixed Datatypes & List Indexing

Mixed Data Types

A list can also contain different data types in the same list.

Example:

list1 = ["abc", 34, True, 40, "male"]

print(list1)

Output:
['abc', 34, True, 40, 'male']

List Indexing

Every item in a list has an index number.

Indexing starts from 0.

Example:

thislist = ["apple", "banana", "cherry"]
Item Index
apple 0
banana 1
cherry 2

To access an item, use its index number.

Example:

thislist = ["apple", "banana", "cherry"]

print(thislist[1])

Output:
banana

6. The type() Function & The list() Constructor

The type() Function

From Python's perspective, lists are objects with the data type list.

Example:

mylist = ["apple", "banana", "cherry"]

print(type(mylist))

Output:
<class 'list'>

The list() Constructor

Python also provides a list() constructor for creating lists.

Example:

thislist = list(("apple", "banana", "cherry"))

print(thislist)

Output:
['apple', 'banana', 'cherry']

Note: The list constructor uses double parentheses because the values are passed as a tuple before being converted into a list.

7. Summary

Summary

  • Lists store multiple items in a single variable.

  • Lists are created using square brackets [].

  • Lists are ordered.

  • Lists are changeable.

  • Lists allow duplicate values.

  • List indexing starts from 0.

  • The len() function returns the number of items in a list.

  • Lists can contain different data types.

8. Exercises

Class Exercise

  1. Create a list containing five fruits and print it.

  2. Create a list containing five numbers and print it.

  3. Create a list containing your name, age, and state.

  4. Print the length of the following list:

cars = ["Toyota", "Honda", "BMW", "Ford"]
print(len(cars))
  1. What is the output of the following code?

mylist = ["apple", "banana", "cherry"]
print(mylist[1])