1 00:00:00,810 --> 00:00:01,830 Instructor: Welcome back. 2 00:00:01,830 --> 00:00:04,920 Let's talk about our next data type, 3 00:00:04,920 --> 00:00:08,523 and it's a big one, a very, very useful one. 4 00:00:09,750 --> 00:00:11,493 It's called list. 5 00:00:12,540 --> 00:00:17,040 And list is an ordered sequence of objects 6 00:00:17,040 --> 00:00:18,423 that can be of any type. 7 00:00:19,740 --> 00:00:22,770 So you can think of them as strings, right? 8 00:00:22,770 --> 00:00:26,100 We had strings previously that we learned about, 9 00:00:26,100 --> 00:00:29,520 except that each sequence of this string, 10 00:00:29,520 --> 00:00:32,070 well, was a string, was a letter 11 00:00:32,070 --> 00:00:35,670 or a number wrapped in quotation marks. 12 00:00:35,670 --> 00:00:39,540 Lists, on the other hand, looks something like this. 13 00:00:39,540 --> 00:00:42,240 Let's say we create a variable, li, 14 00:00:42,240 --> 00:00:46,530 and lists we denote with square brackets, 15 00:00:46,530 --> 00:00:48,510 and inside of these square brackets, 16 00:00:48,510 --> 00:00:50,580 we can have different objects. 17 00:00:50,580 --> 00:00:55,260 So for example, we can have 1, 2, 3, 4, 5. 18 00:00:55,260 --> 00:00:57,810 We can also have, let's say li2, 19 00:00:57,810 --> 00:01:02,173 and this is going to have a, b, c, 20 00:01:04,530 --> 00:01:09,030 and it can have any collection of items that we want. 21 00:01:09,030 --> 00:01:11,220 We can even mix and match, 22 00:01:11,220 --> 00:01:16,220 and say that we have one, two, then a, 23 00:01:16,710 --> 00:01:20,220 then maybe even the Boolean value true. 24 00:01:20,220 --> 00:01:23,223 So all of these are lists. 25 00:01:24,150 --> 00:01:28,950 Now, lists are extremely important, 26 00:01:28,950 --> 00:01:31,380 and in other programming languages 27 00:01:31,380 --> 00:01:35,100 you might have heard the word arrays. 28 00:01:35,100 --> 00:01:39,840 So in Python, lists are a form of array, 29 00:01:39,840 --> 00:01:42,900 and later on when we get into the modules section 30 00:01:42,900 --> 00:01:45,660 of the course, we will talk about the difference 31 00:01:45,660 --> 00:01:47,190 between lists and arrays. 32 00:01:47,190 --> 00:01:48,720 But if you are coming 33 00:01:48,720 --> 00:01:50,880 from a different programming background, 34 00:01:50,880 --> 00:01:54,543 then lists are like arrays in your language, 35 00:01:55,530 --> 00:01:57,930 a collection of items. 36 00:01:57,930 --> 00:02:00,420 Now, the neat thing about lists is 37 00:02:00,420 --> 00:02:04,320 that it's the first data structure that we're learning. 38 00:02:04,320 --> 00:02:07,443 Now, what is a data structure? 39 00:02:08,400 --> 00:02:10,800 Data structure is a very important concept 40 00:02:10,800 --> 00:02:12,660 in programming languages. 41 00:02:12,660 --> 00:02:16,710 It's a way for us to organize information and data 42 00:02:16,710 --> 00:02:21,710 into, let's say, a folder or a cupboard or a box, 43 00:02:22,350 --> 00:02:25,500 so that these data structures can be used 44 00:02:25,500 --> 00:02:27,180 with different pros and cons. 45 00:02:27,180 --> 00:02:31,230 For example, you have a fridge where you store your food, 46 00:02:31,230 --> 00:02:33,360 and fridges are really, really good 47 00:02:33,360 --> 00:02:36,450 at putting your food inside, keeping it cold, 48 00:02:36,450 --> 00:02:37,980 and then taking it out. 49 00:02:37,980 --> 00:02:39,900 Or you might have a backpack. 50 00:02:39,900 --> 00:02:41,490 A backpack is really really good 51 00:02:41,490 --> 00:02:43,080 to stuff everything in there. 52 00:02:43,080 --> 00:02:45,270 But when you're looking for things in a backpack, 53 00:02:45,270 --> 00:02:46,800 it's really, really hard. 54 00:02:46,800 --> 00:02:49,710 So you can think of data structures as similar to that, 55 00:02:49,710 --> 00:02:52,050 a container around your data 56 00:02:52,050 --> 00:02:54,990 that has different pros and cons 57 00:02:54,990 --> 00:02:59,070 of accessing that data, removing that data, writing data. 58 00:02:59,070 --> 00:03:02,190 But that's something we'll get into a little bit later. 59 00:03:02,190 --> 00:03:05,010 The key here is that these square brackets 60 00:03:05,010 --> 00:03:08,370 allow us to contain information and data, 61 00:03:08,370 --> 00:03:13,050 like strings, integers, floats, if we want to 62 00:03:13,050 --> 00:03:15,810 Booleans, into a contained fashion. 63 00:03:15,810 --> 00:03:17,820 So let's think of a good example here. 64 00:03:17,820 --> 00:03:19,860 What if we had a shopping cart? 65 00:03:19,860 --> 00:03:21,813 Let's say we're Amazon here, 66 00:03:22,800 --> 00:03:26,550 and then Amazon has the Amazon shopping cart, 67 00:03:26,550 --> 00:03:29,700 and in here we can collect different things that we want. 68 00:03:29,700 --> 00:03:33,010 Maybe we collect some, I don't know, notebooks 69 00:03:33,870 --> 00:03:34,703 And you know what? 70 00:03:34,703 --> 00:03:35,550 Let's get some gadgets. 71 00:03:35,550 --> 00:03:39,540 Let's get some, maybe some sunglasses. 72 00:03:39,540 --> 00:03:43,380 We can add different items here, different strings, 73 00:03:43,380 --> 00:03:45,903 different data into this cart. 74 00:03:46,980 --> 00:03:48,900 And now, just like we saw in strings, 75 00:03:48,900 --> 00:03:52,533 we can access the Amazon cart in different ways. 76 00:03:53,760 --> 00:03:56,760 For example, I can access it, again, 77 00:03:56,760 --> 00:04:01,110 with square brackets and simply say, I want item zero. 78 00:04:01,110 --> 00:04:02,583 So if I print here, 79 00:04:04,200 --> 00:04:05,613 and do amazon_cart, 80 00:04:07,170 --> 00:04:08,850 look at that, I get notebooks. 81 00:04:08,850 --> 00:04:09,963 The second item, 82 00:04:12,120 --> 00:04:14,490 I get sunglasses. 83 00:04:14,490 --> 00:04:16,293 What about the third item? 84 00:04:18,930 --> 00:04:22,023 Nope, list index out of range. 85 00:04:23,370 --> 00:04:25,020 But this should make sense now. 86 00:04:25,020 --> 00:04:29,340 This is a list where we're accessing the index of, 87 00:04:29,340 --> 00:04:31,110 but it only contains two items. 88 00:04:31,110 --> 00:04:33,810 So if we're going zero, 1, 2, 89 00:04:33,810 --> 00:04:35,760 the third item, nothing exists. 90 00:04:35,760 --> 00:04:38,100 So our program says that doesn't work. 91 00:04:38,100 --> 00:04:40,170 You're doing something wrong. 92 00:04:40,170 --> 00:04:45,170 And just like strings, these list items are in memory 93 00:04:45,570 --> 00:04:47,790 in their separate bookshelf, right? 94 00:04:47,790 --> 00:04:49,470 But one right next to each other. 95 00:04:49,470 --> 00:04:52,950 So we can go 0, 1, 2, 3, 4, 5, 96 00:04:52,950 --> 00:04:56,370 so on and so forth until the list ends. 97 00:04:56,370 --> 00:04:59,280 All right, let's learn about lists a lot more 98 00:04:59,280 --> 00:05:00,963 in the next video, bye-bye.