✦ Python Foundations Collections module

Concept 08 · List Operations & Methods

Change a list
with clear operations.

Lists can grow, shrink, and change as your program works with a group of values.

01 Learn02 Try03 Predict

List methods change a list in useful ways.

Use <code>append()</code> to add at the end and <code>insert()</code> to add at a chosen position.

tasks = ["Learn Python", "Practice loops"]
tasks.append("Build a project")
print(tasks)

append() adds one new item after the current final item.

['Learn Python', 'Practice loops', 'Build a project']

remove(value) removes a matching value. pop(index) removes an item at an index and returns it.

↳

Important difference: remove() looks for a value; pop() works with a position and gives the removed item back.

Remove and keep an item
items = ["book", "pen", "bag"]
items.remove("pen")
removed = items.pop(1)
print(items)
print(removed)

After removing "pen", the list shifts left, so index 1 then refers to "bag".

Check a list
numbers = [5, 10, 15]
print(len(numbers))
print(10 in numbers)

len() counts items and in checks whether a value is present.

Python Playground

Loading Python runtime…

Run each operation, then change an item or method and observe how the list changes.

list_operations.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 list after append, then remove the item at index 1 with pop.

numbers = [5, 10, 15]

numbers.append(20)
numbers.pop(1)

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

Your learning mentor

Ask Sloby about list operations

Describe what feels unclear about adding, removing, or changing list items.

Hi! I'm Sloby. Let's work through Python list operations.

What will this program print, and why? Explain remove, pop, and the changed index.

items = ["book", "pen", "bag"]

items.append("laptop")
items.remove("pen")
removed = items.pop(1)

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