✦ Python Foundations Collections module

Concept 06 · Lists

Keep related values
together in order.

Lists let Python keep several values in one ordered, changeable collection.

01 Learn02 Try03 Predict

A list stores multiple values in a defined order.

Write values between square brackets and separate them with commas. Each value has a position, so Python can find or change it later.

fruits = ["apple", "banana", "orange"]
print(fruits)

The name fruits refers to one list containing three strings in order.

['apple', 'banana', 'orange']

Lists are mutable: you can replace an item without creating a new list. len() tells you how many items the list contains.

↳

Remember: List positions use indexes that begin at 0, not 1.

Change one item
fruits = ["apple", "banana", "orange"]
fruits[1] = "pear"
print(fruits)

Index 1 is the second item, so only "banana" changes to "pear".

Python Playground

Loading Python runtime…

Change an item or add another fruit, then run the code in your browser.

lists.pyPython
OutputWaiting for Python
The browser runtime is loading. You can still edit the example code.

Pyodide runs Python in a browser Web Worker. It is stopped and restarted if code keeps running. Browser execution is not a complete security boundary; do not enter secrets or rely on it for untrusted code isolation.

What will this program print?

Follow the index that is changed before print() runs.

colors = ["red", "blue", "green"]
colors[0] = "yellow"

print(colors)
Choose the output
Sloby, the Python AI Tutor mascot

Your learning mentor

Ask Sloby about lists

Describe what feels unclear about list order, indexes, or changing items.

Hi! I'm Sloby. Let's explore Python lists together.

What will this program print, and why? Explain which list item changes.

numbers = [10, 20, 30]
numbers[1] = 50

print(numbers)
Python AI Tutor · Learn by understanding, not just by running code.