Let's learn about Lists and their usage in Python

Creating a list

A Python list is similar to an array in other languages. In Python, an empty list can be created in the following ways.

my_list = []
my_list = list()

As you can see, you can create the list using square brackets or by using the Python built-in, list. A list contains a list of elements, such as strings, integers, objects or a mixture of types. Let’s take a look at some examples:

my_list = [1, 2, 3]
my_list2 = ["a", "b", "c"]
my_list3 = ["a", 1, "Python", 5]

The first list has 3 integers, the second has 3 strings and the third has a mixture. You can also create lists of lists like this:

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy