Lists
Explore the fundamentals of Python lists including creation, indexing, slicing, and important built-in functions. Understand list copying versus referencing, how to use list methods like append and pop, and how to handle multi-dimensional lists carefully to avoid common pitfalls. This lesson helps you work confidently with this versatile data structure.
We'll cover the following...
Definition
A Python list is an indexable sequence of values, which may not necessarily all be of the same type. The first index is 0. You can create a list by writing a comma-separated sequence of values enclosed in brackets, [].
Here are a few examples of this:
Arbitrary size lists
In Python, you can create a list of an arbitrary size by “multiplying” it by an integer. The integer must be to the right of the * operator.
You can observe this in the following example:
Shallow copy effect in lists
Let’s assume we have a variable called x. If x is a list; and you say y = x, then y becomes another name for the same list, not a copy of x. That is, any change you make to ...