Lists
7 min · Python
Hold many values under one name, and reach for the one you want.
Enemy 1 of 5
So far every variable has held exactly one value. A list changes that — it holds several values in order, all under one name, inside square brackets and separated by commas. Think of it as a single labeled shelf with multiple slots, instead of one labeled box.
Lists are one of Python's most-used features because so many real problems are naturally "a bunch of things": a leaderboard of scores, a roster of players, the lines of a file. Rather than creating fruit1, fruit2, fruit3 as separate variables (which quickly becomes unmanageable), you keep them together in one list and can loop over, sort, search, or grow it as a whole.
Run this to make a list of fruits and print the whole thing.
Loading editor...