In Level 11, we learned how to create a list, but a static list isn't very helpful if your program needs to change. Imagine a game where you pick up a new item—the list needs to grow! In Level 12, we explore LIST METHODS. These are built-in Python tools that allow you to add, remove, and sort items within your lists. At FLORA WORLD CODING, we consider this the "gardening" phase of coding, where you learn to manage your digital inventory.
The two most important methods you will use are .APPEND() and .REMOVE(). When you use LIST_NAME.APPEND("ITEM"), Python adds that item to the very end of your list. If you need to get rid of something, LIST_NAME.REMOVE("ITEM") will search the list and delete the first instance of that item. It’s important to note that these methods "mutate" or change the original list permanently, so you have to use them with care!
Why do ADSENSE-approved sites teach these methods early? Because dynamic data is what makes modern apps work. Your "Followers" list on social media uses APPEND when someone hits follow and a removal method when they unfollow. By mastering these commands, you are moving beyond simple scripts and starting to build logic that can handle real-world, changing information. This is a vital step toward creating interactive databases and gaming systems.
| METHOD | WHAT IT DOES |
|---|---|
.append(x) |
Adds item x to the end of the list |
.remove(x) |
Removes the first item that matches x |
.sort() |
Organizes the list alphabetically or numerically |
len(list) |
Tells you how many items are in the list |
CREATE A LIST CALLED INVENTORY. USE .APPEND() TO ADD THREE ITEMS. THEN, USE PRINT(LEN(INVENTORY)) TO SEE HOW MANY ITEMS YOU HAVE. FINALLY, TRY TO .REMOVE() ONE ITEM AND PRINT THE LIST AGAIN TO SEE IT DISAPPEAR!