Learn how to store multiple items in one variable using a Python list. Lists are useful for fruits, game scores, names, shopping items, and much more.
Make a list using square brackets, like ["apple", "banana", "cherry"].
Python starts counting at 0, so mylist[0] gets the first item.
Replace items, remove items with pop(), and print your final list.
Start with the video, then complete the list activities.
Practise creating, changing, and using Python lists.
Here is a list calledmylist in Pyhton which contains three fruits.
mylist = ["apple", "banana", "cherry"]
Now you try and create a lsit of your own so that it contains four cars with "Toyota" in the 2nd index.
Open the interactive activity and build a list by dragging fruits into the list slots. Watch how the fruit pile changes when you add or remove items.
Create and edit a fruit list using real Python.
mylist[1] = "grapes" and mylist.pop().Write Python code that does all five steps:
mylist with 5 fruits.0."grapes".pop().Example starting list:
mylist = ["apple", "banana", "cherry", "melon", "pear"]
Expected idea: first print should be apple, and the final list should contain grapes as the second fruit.
Move on when your list challenge passes.