How to Use Lists in Python

未能成功加载,请稍后再试
0/0

In this section we're going to look at the built in data structures in Python, which are extremely important when building real applications.

First we're going to look at lists, and then we'll look at tuples, sets, and dictionaries.

So earlier you have seen that we can use square brackets to define a list or a sequence of objects.

In between these brackets we can have objects of any type, so we can have a list of strings, like this, of strings like this, and then assign it to a variable like letters, we can also have a list of numbers, booleans, or even a list of lists, let me show you.

So here we have a list, each item in this list will be a list itself.

So here's the first item, which is a list of two items, now let's add another item to our main or parent list, this item is also a list with two items.

So now we have a matrix, which is a two dimensional list.

Now let me show you some cool tricks.

Let's say you want to have a list of 100 zeros.

You don't want to manually create that like this, that's very ugly.

下载全新《每日英语听力》客户端,查看完整内容