what is a List in Python?

Video Notes:

What I use to learn (the BEST IT training): https://ntck.co/itprotv (30% off FOREVER) *affiliate link

FREE Python lab: https://ntck.co/pyep7

🔥🔥🔥🔥Extra Labs and Quizzes at NetworkChuck Academy: https://ntck.co/python

In this installment of NetworkChuck’s Python series, Chuck is going to show you how to use Lists in Python. You will learn how to create your own Python List and also how to Print out the items from your Python List that you are supposed to bring while you prepare for your camping trip!

🔥🔥Get access to all of my courses plus more by joining the NetworkChuck Academy!: https://ntck.co/NCAcademy

**Sponsored by ITProTV

0:00 ⏩ Intro
0:26 ⏩ [“Let’s”, ”Get”, “Started!”]
0:44 ⏩ The BEST IT training!
1:50 ⏩ Creating your camping list variable!
2:44 ⏩ It’s all coming together!(Kronk voice)
3:18 ⏩ What is a Python list? Ft. Bernard Hackwell
5:24 ⏩ Let’s make our campsite list!(it might be a little dangerous!)
6:42 ⏩ What are you bringing on the trip?
7:35 ⏩ Print out what you are bringing!
8:21 ⏩ Don’t forget the 0!
9:50 ⏩ Time to break your brain!
10:06 ⏩ What the junk is a negative index?
11:05 ⏩ I forgot to print the whole list
11:37 ⏩ [“Outro”]

This is a Python list and they are ridiculously powerful and pretty fun to play with. So in this episode, get you coffee ready because recovering the what and why of this incredible data structure and how it will open up a whole new world of Python. Goodness. You ready? Let’s dive in.
Okay, here we go. One more sip of coffee let’s get started. So we covered a variable. We created a sign, a simple piece of data, and we can use it everywhere in our Python script. It’s awesome. But let me show you when it’s not awesome because you and I we’re going on a camping trip, but you didn’t know. Yeah, come on. But first we need our Python lab up and running. Let’s get that running real quick. So if you haven’t already, you’re in the side panel of the course, either over here or over here, I never know where to look. Go ahead and launch our lab for today. Lab one. So we’re going on a camping trip and like all camping trips. We need a ton of stuff. Tent, sleeping bags, raspberry pies, lash drives, ether night, cables, marshals, just things like that, right? The essentials.
Now here’s what I need you to do. I need you to create a variable, let’s name it, camp underscore stuff. And I want that to equal all the supply eyes. We have to bring, go ahead and do it right now. In fact, we’ll, we’ll do it together right now. Let’s do it. So using the knowledge we learned so far in this series, we might do this camping stuff. Variable created let’s have it equal something equals and you know, we’ll just start typing in the stuff. Tent, sleeping bags, jump forward in time and have it already there. And if we print the variable camping stuff and we run our code, go and click around at the top there. That works. But it doesn’t because right now this is one big fat string. It’s bloated. It’s ugly. I hate it. It’s really hard to use. And honestly, kind of stupid. We can do better instead of storing all of our data into one big fat string, we can try out something really cool, something amazing, something fun, something, life changing something called a Python list.
Let’s do this, which honestly makes total sense. Cause we’re trying to make a list of things we gotta bring. Hey, Python list. It just, it just all adds up. It’s all coming together here. So I’m gonna create a new variable called camping underscore list just like before, but here comes the craziness. Don’t worry. I’ll walk you through it. Brackets. That’s the game changer right there. Buckle your seatbelt, coffee break and time to build the list. You can step forward in time. Just go ahead and jump. Jump forward in time. Woo done. That was exhausting. You know the coffee break. Okay. And also I want you to do the same thing. So I know it’s a lot of typing, whatever. Just, just do it. It’s not too hard. This right here is a Python list and it’s so awesome. So many reasons, way better than this idiot over here. And I will go into why, but first let’s get a really nerdy definition on what a Python list is. Go ahead, Bernard. A
Python list is an ordered and changeable collection of data objects. Unlike an array which can contain objects of a single type, a list can contain a mixture of objects.
Now first, before we talk about how awesome this is, I want you to print the type of data. This camping list variable is just go ahead and print it real quick. The type. Do you remember how here’s, how we do it? Print using our print function. And then in the print function, we use our type function and then I’ll just print the type of the camping list. Cause I don’t wanna lie to you. I gotta prove to you that this is a data structure called list. Let’s go ahead and run the code run. And there is suckers that told you a data class, a data structure called list. Oh man, I’m telling you, this is gonna open up so many doors to Python coding. We’re gonna spend a lot of time like actually playing with this. Okay? Anyways, I’m excited for you. Let’s keep going.
I’m gonna delete this stuff real quick. We’ll talk about what the junk is going on with this stuff up here. Now you can recognize a list because it’ll always have opening and closing brackets, bam and bam. It has to have those. That’s what a list needs. And then inside that list is where we have our data and notice how the data is separated by a comma there. They all are now real quick. Let’s bask in the awesomeness of a list. So up here, right? It was a big ugly strings. One big fat string down here. We got a bunch of individual strings. Like how many we have here. Count for me. I’ll do it. We have 10 individual pieces of data inside this one variable so much better, right? You’re probably thinking, well, why is it so much better? We’ll get to it. We’ll get to, I’ll show you a, a case here, but can I tell you something else?
Cool about a list. It can have more than just string data types inside of it. Let’s try it out actually. So let’s create a new list and I wanna name this camp underscore site. And actually, you know, I want you to do this and here’s the data I want you to put in there. It’ll be like campsite information. First, the name of our camp will be, or the camp site will be crystal lake sounds perfectly safe. And then of course we’ll need our site number, which will be 4 0 4. And then they expect a temperature of that day. It’s gonna be a Balley 89.3 degrees. And then one more piece of data. Is this place dangerous, true or false? Um, it’s gonna be true. It is dangerous. So make our campsite list. Go for it. Now pause on pause, coffee break. Let’s go ahead and do it to make our list.
We’ll do an opening bracket and our amazing Python rep here will make it for us. First data. Crystal lake is a string. Cool. We got that comma space. You space is optional, but it’s best practice. Do a space just cuz it looks pretier and we’re all about pre next piece of data. 4 0 4. That’s gonna be a number, an Eger, right? Duh. Just like that. No quotes space com space temperature. 89.3 degrees. Fahrenheit people I’m in. I’m in America. Get, get over it. And then finally is it dangerous? Yeah. True. Cool. So how amazing is this here in this list? We have four different types of data, right? We get a string. We have an inte, a float and a bullion. I don’t know why I say it like that. I’m sorry. So now I think you’re starting to see how amazing the list are. They can hold multiple pieces of data and different types of data.
Doesn’t that make you just a little bit excited? If it doesn’t man, sip some more coffee and then come back to me. Okay. Rewind. Now here comes the killer killer. The killer part of list. I, I talked about this. If you are what professor Bernard said they are ordered. What does that mean? I’ll explain it by showing you two amazing things. You ready for this? Okay, here we go. Let’s say that out of our camping list, I need to assign, who’s going to bring what on the camping trip. So for example, me, I’m going to bring coffee, duh. Right? You sell that coming and you you’re coming, right? Yeah. You’re coming. You’re gonna bring marshmallows because they’re delicious. Here’s how it can assign that data with a list. Oh, it’s so powerful. Watch this. This is gonna blow your mind. I’ll create the variable me and have that equal.
Watch this, the list, camping list and then do some brackets. And then in those brackets, I’m gonna put the number four. What just happened? What am I doing? Watch. I’m going to print me the variable me. Let’s run it run. Did you just see that? Sorry. I’m I’m I know it’s it seems like I’m overexaggerating but I’m really this excited about it. I’m not kidding right here. It printed just coffee. Just that one. String. That one piece of data in our list. Now go ahead and do the same thing for you. Do you remember what you’re bringing? Go ahead and do it real quick. Pause the video, do the same thing for you and then print out that one item go UN pause. Okay. How would you do that? Create the variable you have that equal camping list and then brackets. Let’s see if you could figure this out.
You were bringing marshal, which is the last in our list, which means marshmallows will be nine. Did you get that right? I’ll explain why it’s nine here in a second, but let’s go and print it out. I’ll put it below me printing you now and run coffee and marshmallows. Yes. So when I say the list is ordered, or you might see people talking about it being in a, in a sequence or sequenced, when you put your stuff, that data into your list, the order you put it in there, it stays the same, which is great because we can do things like reference the individual items in that list. So when it says ordered, when it says sequence, it just means, Hey, that’s stuff you put in there. It’s in that same order all the time. Unless we change it, which we’ll talk about later, but then real quick, hold on.
Why was coffee four? Because if we’re looking at our list here, we got 1, 2, 3, and then four raspberry pie is four. Coffee should have been five, right? No, we’re done with computers and, and computers have to be difficult. Sometimes you might realize and remember, and know that computers always start counting with zero. So what they do, so test would be zero. Then 1, 2, 3, bringing us at four with coffee, which is why marshmallows instead of being 10 would actually be nine. So in an I a list with 10 items, your last number will always end up being nine. Just keep that in mind. That that always messes me up whenever I’m dealing with list. So I just have to like manually consciously. Remember it. It’s fine though. But this right here, what we did here is super powerful and it’ll become more how powerful that is.
Um, when we do something later, I can’t tell you yet. I wanna tell you, but you have to wait, but diving deeper into that. You’ll also see lists referred to as, um, indexed. That’s kinda just another way of saying ordered, ordered sequenced indexed. And when I say indexed, it just means that each item on our list is assigned a number. It just, it just the order it’s in. And when we re a list like this, we’re calling out the index of that item. We’re going, Hey, ah, here’s the camping list, item, number four, pull it out. That’s what we’re doing. How cool is that? And you probably already noticed that when we are trying to reference a item in a list, when we index it, we use brackets. Now, quick coffee break. I wanna cover one more thing that might break your brain, but can we just do it real quick?
It’s gonna be fun. It’s really fun. A promise coffee break. It has to do with indexing. We’re gonna index one more time and actually I’m gonna change you real quick. I’m gonna change you, your, your variable, you you’re still bringing marshmallows, but I’m gonna change the way I find marshmallows with that list. Watch I’m gonna change that nine two. This is weird. Negative one. Now, what do you think is gonna happen when we print this? Let’s try it out. Let’s run our code. Hey look, stay the dang. Same why? Well that’s called eight and negative index. It does come in handy, but essentially what you’re doing is you’re counting in reverse. So instead of starting a peer, we’re starting all the way back here. So the very last item in our list would be negative one. And you’re probably thinking, well, Chuck nuh should be negative zero.
It’s not just isn’t. You can’t have negative zero. It’s impossible. Anyway. Sorry. I didn’t mean to get little angry with you. I’m just kidding. I wasn’t, but that’s a handy way to access the last item in your list. You’re probably thinking, well, that’s kind of stupid. Why would we ever do that? Well, you know, sometimes you may not know how big a list is and other times there might be a very good reason. They’ll access the last item in a list. You’ll find out that later, but let’s try it one more. What happens if we do go and change it to negative two negative two. Let’s try it out. Run our code. Bam, beard oil. It’s now the second to last item in the list and real quick, I can’t believe we haven’t done this yet. Shame on me. Let’s go ahead and print the entire list at the very end here.
Just print camping list run. Cool. So when we print the camping list, guess what? It looks just like our list that we have there. Let me scroll up. See, can see it. The only difference is that it uses single quotes instead of double quotes. It breaks our standard. It’s okay though. We’ll forgive it. Now. I told you didn’t I, I wasn’t lying. Python list are really fun and really powerful. Now you probably understand the power they have even just now, but you have no idea what’s coming up. What you can do with these is gonna, you know, it’s just gonna be mind blowing. So yeah, I mean, what are you waiting for? Go ahead and jump to the next episode. Go watch it. I’ll see you there. Bring your coffee. I’ll have a fresh batch when that.

Check Out Network Chuck's Coffee and MERCH Shop