After reading lesson 25, you’ll be able to
- Build Python lists
- Add items, remove items, and modify items in Python lists
- Perform operations on list elements
Mutable data types are types of objects on which you can perform operations, such that the object’s value is modified; the modification is done in place, so to speak, so no copy of the object is made. There’s a need for data types that are mutable, especially when working with large amounts of data; it’s more efficient to modify data stored directly instead of copying it into a new object with every operation.
Instead of creating new objects, it’s sometimes useful to reuse an object and modify its value. This is especially true when you have an object that represents an ordered collection of other objects. Most programming languages have a data type to represent this type of ordered collection that you can mutate. In Python, this is called a list. A list is a new type of object that you haven’t seen before. It represents an ordered collection of other object types. Among many others, you can have lists of numbers, lists of strings, or even a list of a mix of object types.