Imagine having a special box where you can keep lots of important things together. In Python, a list lets you store multiple items inside a single variable.
Lists are ordered collections of data, written inside square brackets [ ]. You can store numbers, words (strings), or even other lists.
Lists are powerful because you can add, remove, and check items easily.
💡 Analogy: A list is like a grocery list—you decide the order, you can add new items, remove ones you don't need, and find exactly what you're looking for.
By the end of this lesson, you will be able to:
Create and modify lists in Python.
Access elements using indexing.
Use list methods to manipulate data efficiently.
Lists – Ordered collections of items stored in square brackets ([ ]).
Indexing – Accessing elements in a list using their position (fruits[0] gets the first item).
Appending – Adding new elements to a list using .append() (fruits.append("grape")).
len(myList) -
List slicing – Extracting a portion of a list using indices (fruits[1:3]).
Mutable data structures – Lists can be changed after creation by adding, removing, or modifying elements.
Our friends Craig & Dave explain Arrays (Lists in Python).
In Python, a list is a way to store multiple values in a single variable. You can create a list by placing items inside square brackets [], separated by commas.
fruits = ["apple", "banana", "cherry"]
print(fruits)
Task 1: Create a list called colors that contains three color names. Print the list.
Example output:
['red', 'green', 'blue']
Each item in a list has a position (called an index), starting from 0. You can access items using these indices, including negative numbers to count from the end.
print(fruits[0]) # First element
print(fruits[-1]) # Last element
Task 2: Create a list of five different countries. Print the second and last country in the list.
Example output:
['Japan', 'Brazil', 'Canada', 'Italy', 'Kenya']
Brazil
Kenya
You can start with an empty list and add elements to it using the .append() method. This is useful when you're building a list dynamically.
students = []
students.append("Liam")
students.append("Sofia")
students.append("Carlos")
print(students) #prints all elements in the list
Task 3: Write a program that asks the user to enter three hobbies one by one. Store them in a list using .append() and print the final list.
Example output:
Enter a hobby: painting
Enter a hobby: swimming
Enter a hobby: reading
['painting', 'swimming', 'reading']
Using a for loop, you can go through each item in a list and do something with it, like print a message.
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print("I like", fruit) #outputs the elements one at a time
Task 4: Create a list of three sports you enjoy. Use a for loop to print a sentence about each sport. The sport will be pulled from your list and the rest of the sentence will be text that you provide as a string.
Example output:
I enjoy playing football
I enjoy playing tennis
I enjoy playing swimming
Sometimes you want to loop through a list using index numbers. You can use range(len(list)) to do that and access each item by its index.
fruits = ["apple", "banana", "cherry"]
for i in range(len(fruits)):
print("Fruit", i, "is", fruits[i]) #outputs using index-value
Task 5: Make a list of five movie titles. Use a for loop with range(len(...)) to print each movie with its position in the list.
Example output:
Movie 0 is Inception
Movie 1 is The Lion King
Movie 2 is Spider-Man
Movie 3 is Frozen
Movie 4 is Toy Story
Forgetting that lists start at index 0: In a list with 3 items, list[3] will cause an IndexError. You should use list[0], list[1], and list[2].
Overwriting a list accidentally when using .append()
Example:
Incorrect: fruits = fruits.append("orange") (this changes fruits to None)
Correct: fruits.append("orange") (this adds "orange" to the list properly)
Mixing up brackets: Always use square brackets [ ] for lists. Round brackets ( ) are for functions or tuples.
Using = instead of .append() to add items
Example:
Incorrect: fruits = "apple" (this replaces the whole list)
Correct: fruits.append("apple") (this adds a new item without losing the list)
Trying to print multiple items without a loop or index: print(list) shows the whole list at once, but if you want to print each item separately, you need a for loop.
Forgetting quotation marks around strings
Incorrect: fruits = [apple, banana]
Correct: fruits = ["apple", "banana"]
Forgetting commas between list items
Incorrect: fruits = ["apple" "banana" "orange"]
Correct: fruits = ["apple", "banana", "orange"]
🔗 Practice on W3Schools: Lists Tutorial – Learn how to create, modify, and use lists in Python. There are additional methods to make working with Lists easier which you can practice here.
🔗 Try It Online: Run Your Code Here – Test your Python code instantly.
Create an empty list called my_list.
Use a for loop to ask the user to input three hobbies, one at a time. After each input, use .append() to add the hobby to my_list.
Print the full list to check all hobbies were added correctly.
Print the first and last items in my_list.
Use another for loop to print a full sentence for each hobby, such as "I love [hobby]".
Example output from this program:
Enter a hobby: painting
Enter a hobby: swimming
Enter a hobby: cycling
['painting', 'swimming', 'cycling']
painting
cycling
I love painting
I love swimming
I love cycling
Write the example from this lesson, making sure to include:
✅ A list storing multiple values
✅ Accessing elements using indexing
✅ A print() statement displaying the list
Read the example code before writing!