1 00:00:00,620 --> 00:00:04,040 So you know how we can create a string by placing some characters in quotes? 2 00:00:04,040 --> 00:00:06,320 Well, this is known as a string literal. 3 00:00:06,320 --> 00:00:08,360 Well, there's a list literal as well, 4 00:00:08,360 --> 00:00:12,100 and it's created by surrounding your items and hard brackets and 5 00:00:12,100 --> 00:00:15,680 you can put your objects inside those brackets and separate them by commas. 6 00:00:16,990 --> 00:00:20,080 Why don't you click the launch works space button before I say something offensive in 7 00:00:20,080 --> 00:00:20,660 sign language? 8 00:00:21,810 --> 00:00:23,580 Okay, so let's get exploring. 9 00:00:23,580 --> 00:00:27,347 My favorite place to explore is the REPL, so let's launch the Python shell, so 10 00:00:27,347 --> 00:00:28,370 we'll type python. 11 00:00:28,370 --> 00:00:30,940 All right, so let's get exploring. 12 00:00:30,940 --> 00:00:37,370 So I can create new list with an opening hard bracket and a closing hard bracket 13 00:00:37,370 --> 00:00:42,930 and that is an empty list, just like a double quoted empty string. 14 00:00:42,930 --> 00:00:46,050 Let's look at how to add items to a list. 15 00:00:46,050 --> 00:00:48,200 You really just put data in here. 16 00:00:48,200 --> 00:00:51,260 Let's create another of these empty lists and let's put some data in there. 17 00:00:51,260 --> 00:00:55,820 So, for instance, if I was making a list of programming languages that you 18 00:00:55,820 --> 00:00:59,410 could learn here on Treehouse, now obviously let's start with Python. 19 00:01:01,320 --> 00:01:05,930 And that's a string and then we can add a comma, to separate our values, right? 20 00:01:05,930 --> 00:01:13,890 So next up, let's do JavaScript, and let's add another one, let's add a Java. 21 00:01:13,890 --> 00:01:16,710 JavaScript and Java are different languages by the way. 22 00:01:16,710 --> 00:01:18,720 And of course we teach many more languages, 23 00:01:18,720 --> 00:01:20,860 but let's just stop here for right now. 24 00:01:20,860 --> 00:01:25,700 So I'm gonna press enter and you'll see that we got a list object created. 25 00:01:25,700 --> 00:01:29,580 And as you know, we can label that object so that we can keep it around. 26 00:01:29,580 --> 00:01:32,940 So let's create our variable and assign it a new list. 27 00:01:32,940 --> 00:01:37,160 Let's keep with our languages idea, so let's say languages = and 28 00:01:37,160 --> 00:01:44,610 we also teach C#, we teach Ruby, and we teach Swift and there's even more. 29 00:01:45,780 --> 00:01:49,420 So, now that we have a list we can actually check and 30 00:01:49,420 --> 00:01:51,870 see how many items it has. 31 00:01:51,870 --> 00:01:55,170 Just like we use the LEN function to see how many letters were in a string, 32 00:01:55,170 --> 00:01:57,950 we can use the same function to count the items. 33 00:01:57,950 --> 00:02:02,110 So, we can say len of languages, and we should see 3. 34 00:02:02,110 --> 00:02:03,740 Pretty cool, isn't it? 35 00:02:03,740 --> 00:02:07,140 You can pass just about any object to that len function, and 36 00:02:07,140 --> 00:02:10,350 it will most likely give you the answer that you're looking for. 37 00:02:10,350 --> 00:02:14,264 There is a saying in the Python world, there should be one, 38 00:02:14,264 --> 00:02:17,257 and preferably only one obvious way to do it. 39 00:02:17,257 --> 00:02:20,530 And this definitely falls into that Zen of Python. 40 00:02:20,530 --> 00:02:26,380 And therefore, it can be said that the use of the len function is Pythonic, 41 00:02:26,380 --> 00:02:27,800 more in the teacher's notes. 42 00:02:27,800 --> 00:02:29,800 Let's take a look at some coercion too. 43 00:02:29,800 --> 00:02:36,400 So, you might remember that any non-empty string when coerced, to a Boolean is true. 44 00:02:36,400 --> 00:02:38,320 Well, the same holds true for lists, right? 45 00:02:38,320 --> 00:02:41,100 So, if we say what's the Boolean value of languages. 46 00:02:42,280 --> 00:02:46,610 We'll see that it's true and just like how empty string coerce the false so 47 00:02:46,610 --> 00:02:48,240 do empty lists. 48 00:02:48,240 --> 00:02:51,920 So we say bool and we give that an empty list with no items. 49 00:02:51,920 --> 00:02:55,780 It's gonna give us a false, emptiness is falsey. 50 00:02:55,780 --> 00:03:00,810 Sometimes you'll see lists used used in an expression, like if list 51 00:03:00,810 --> 00:03:06,590 this can basically be read like, if there are items in this list, then do this code. 52 00:03:06,590 --> 00:03:09,820 You could also create a list from any iterable which we'll talk about more 53 00:03:09,820 --> 00:03:10,780 here in a bit. 54 00:03:10,780 --> 00:03:15,420 But one data type that we know for sure is iterable is a string, right? 55 00:03:15,420 --> 00:03:20,470 We can iterate through each letter using the for in loop like the banner at a party. 56 00:03:20,470 --> 00:03:22,350 So you can pass in an iterable. 57 00:03:22,350 --> 00:03:24,440 So let's use it, so we'll do this. 58 00:03:24,440 --> 00:03:26,520 We'll say banner = list and 59 00:03:26,520 --> 00:03:29,940 let's say that make this banner was congratulations was the text there. 60 00:03:29,940 --> 00:03:32,920 So we're gonna pass, we're gonna coerce an iterable, 61 00:03:32,920 --> 00:03:36,630 a string iterable, into a list and watch what happens. 62 00:03:36,630 --> 00:03:38,800 So now if we take a look at banner, 63 00:03:38,800 --> 00:03:44,130 you'll see that each element of the list is a letter. 64 00:03:44,130 --> 00:03:48,370 All right, so, I'm in the process right now of putting together a meeting 65 00:03:48,370 --> 00:03:50,080 to talk about some future courses. 66 00:03:50,080 --> 00:03:52,300 And I wanna invite some fellow teachers. 67 00:03:52,300 --> 00:03:56,632 Let's do this, let's make a new file called meeting.py. 68 00:03:56,632 --> 00:04:01,460 So I say a New File, meeting.py, 69 00:04:01,460 --> 00:04:05,930 so what I'll do is I'll create a variable named attendees. 70 00:04:07,010 --> 00:04:10,730 And I'm going to assign it a list. 71 00:04:10,730 --> 00:04:16,879 And that list will have, it will have Ken, Elena, and Treasure. 72 00:04:19,080 --> 00:04:23,830 Awesome, so now let's print out how many attendees we have. 73 00:04:23,830 --> 00:04:27,190 So we'll say, print there are and 74 00:04:27,190 --> 00:04:31,790 we'll just use this multi-parameter 75 00:04:31,790 --> 00:04:36,120 version of print, attendees currently. 76 00:04:40,060 --> 00:04:43,287 Let's go ahead, I'm gonna drop out of this and let's run that file. 77 00:04:43,287 --> 00:04:46,827 So we'll say python meeting.py, 78 00:04:46,827 --> 00:04:52,120 there a three attendants currently, awesome. 79 00:04:52,120 --> 00:04:56,290 Now, one thing I'd like to point out is that lists are mutable, 80 00:04:56,290 --> 00:04:58,250 meaning we can change them. 81 00:04:58,250 --> 00:05:01,570 We can add an attendee to this list if we want to, and in fact, 82 00:05:01,570 --> 00:05:05,310 Ashley just pinged me on Slack and told me she wants to be a part of this meeting. 83 00:05:05,310 --> 00:05:09,110 So let's take a quick break and then come back and learn how to add items to a list.