December 10, 2022
So, Lists in Python are one of those things that at first glance appear easy but grow much more nuanced the more you try to do with them.
For many of these examples, I'm using the Python Shell. The “>>>” is the shell prompt, the unannotated lines below that are the response from the shell. These samples used Python 3.9 and 3.10, both from the Anaconda distribution for Windows.
In Python, as in many other languages, a list is a compound data type, meaning it groups together multiple values under a single variable name:
Make a list under one variable name:
Chop up a list:
Strings can be split into lists:
Add to a list:
Replace an element in a list:
Remove items from a list (3 ways):
Determine the length of a list:
Clear list:
Sorting Lists:
Create a Multi-Dimensional List: