-
Book Overview & Buying
-
Table Of Contents
Python Illustrated
By :
The first type of collection we’ll discuss is lists. A list is probably the most straightforward data type. It’s an ordered collection of items that can be changed. It’s like having a basket where you can toss in your toys, snacks, or anything else you fancy. The items in a list can be of different types. You may wonder what types can be on the list? Well, any type! They could, for example, be numbers, strings, or even other lists! Let’s see how to make them.
We create a list in a similar way to creating another variable. We specify a name followed by an equal sign and then the value. The value is the part where it’s a little different. To create an empty list, you simply use square brackets [] without any items inside.
# An empty list
my_first_list = []
This creates a list called my_first_list that currently holds no items. Soon I’ll tell you how to add items, but let’s first see how we can...