Lists are what you’d think, a list. Lists in Python store multiple values in a single variable (a.k.a. Python object). The values can be mix types, i.e. a single list can contain both numbers or character type values.
To create an empty list, you use the “” brackets.
Assigning values to a list
Let’s create a list and assign it some values, both strings and numeric values.
Indexing and Slicing
Lists can be indexed and sliced just list strings, dictionaries, data frames, and series. Remember that in Python the index starts at 0.
Adding and Changing Values
Lists are mutable. This means we can change the values within it.
Notice how “Honey” replaced “Cherries”.
It is possible to add values to an existing list. When you add a value to an existing list, Python adds the value to the end of the list. To do this, we use the .append() method.
How long is a list?
We can find out the length of lists with the .len() method.
Is something in a list?
You can ask Python if something is in a list. If it is in the list, then Python will return a Boolean value of “True”; otherwise Python will return a Boolean value of “False”.
Concatenation means to combine, join, or add. When you concatenate 2 lists, you are adding the list items together.
Since we assigned the concatenated lists to a new list variable, we retained the original lists with their respective values