Beginning Python Lists

A person’s hands holding pen and eraser above a notepad on a desk, crossing out “bread” from a shopping list.

Lists are one of the most important features in Python. They let us store multiple bits of information together in one tidy container. Instead of creating a new variable for each item, you can bundle them up into a single list.

Think of a shopping list: instead of writing “milk = …, bread = …, eggs = …”, you can keep everything together.

This prints:

The square brackets tell us it’s a list, and the items inside are separated by commas.

Accessing Items by Index

Every item in a list has a position number, known as an index. Python starts counting from zero (which can feel odd at first!).

This is how you grab individual items from a list.

Things to try:

  • Make a list of your top three films. Print only the second one using its index.
  • Try printing the last item in a list by using its index.

Adding Things to a List

Lists aren’t fixed — you can add to them whenever you like. The simplest way is with append(), which puts a new item at the end.

Now biscuits are safely added to the list.

If you want to insert something at a specific position, use insert(index, item).

Here, butter goes in at position 1, pushing the other items along.

Things to try:

  • Start with a list of three colours and add a fourth using append().
  • Use insert() to put something at the start of the list.

Modifying Items in a List

Sometimes you don’t want to add or remove something, you just want to change it. To do this, you can use the index directly.

Now bread has been replaced by butter. Simple!

Things to try:

  • Create a list of three animals, then change the second one to a different animal.
  • Make a list of numbers and replace the first number with a larger one.

Removing Things from a List

There are a few ways to take things out of a list:

  1. By name with remove()
  1. By position with pop(index)

This removes the item at position 1 (bread).

  1. Without giving an index, pop() just removes the last item

Eggs disappear here because they were last in the list.

Things to try:

  • Make a list of four sports and remove one by name.
  • Use pop() to delete the item at index 0.
  • Create a list of three snacks and remove the last one using pop() with no index.

Wrapping Up

Lists are like the backbone of Python programming. They let you group items together, add new ones, update them, or remove them when they’re no longer needed. Once you’ve got the hang of indexes and the basic list functions, you’ll be able to manage information much more easily.

Main Topic

Introducing Python Lists

A cartoon frog smiles while writing “Python Lists” with items flies, worms, insects on a chalkboard in a classroom setting.

This is a Python series introducing lists, their importance, and everyday uses. Light-hearted explanations make coding concepts simple, clear, and fun.

Other Tutorials in this Topic

A cheerful goose sorts colourful books by size on a shelf, with bold text “Sorting Python Lists” against a pale magenta background.

Sorting Python Lists

A practical Python tutorial explaining how to sort lists in ascending and descending order, comparing `sort()` with…

A smiling blacksmith hammers words into metal blocks on an anvil, labelled “cat,” “7,” and “apple,” symbolising immutable Python tuples.

Tuples in Python

A Python tutorial explaining tuples: how to create them, their immutability, practical uses, adding to lists, and…

A person in an orange shirt works along a conveyor belt with boxes, apple, and envelope under text “Iterating Lists” on pale magenta.

Iterating Lists in python

A clear Python tutorial explaining how to loop through lists with for, while, and enumerate, introducing iterators…

A cheerful cartoon monkey sorts bananas from a mixed fruit box into another box on a conveyor belt, with “Filtering Lists” text.

Maps and Filters in python

This tutorial explains how to use Python’s `map()` and `filter()` functions to transform and select list items,…