 Okay, welcome to Python for Java coders. This is part seven where we look at arrays in Java and In Python they're called lists sort of lists are kind of like array lists They're more like array lists than they are like normal arrays in Java So but so I'll talk about kind of how we do things in Python here And even though I don't really have a I didn't have a beginner lesson on our array list over here I'll talk a little bit about lists and you'll kind of see the these similarities between them. So Anyway, let's get started. So you can see over here again in Java Everything has to be declared as a certain type Python. It doesn't so here. We say scores equals new and three the equivalent of that in Python would be something like this We could put we put null or is it null none. That's right. It's none in job in Python none none None but since they're integers, we could just put zero comma zero comma zero This would actually preserves the exact same result because when we create a An array excuse me with no values. It automatically is assigned 0 0 0 by default because it's an integer type an int type and then here you see where we've got Scores now this part's actually the same score zero equals 85 scores one one equals 90 and scores two Equals 100 and so if I went ahead and actually what's nice like just go ahead and print scores here And let's take a look. I see let's run this to make sure this is still running Let's see what that gets us and I'll go ahead and run this at the same time. They're in two different windows Okay, so we got Something went wrong there. That's just still printing out the old thing Unless I just zoomed up too far. There we go. Okay. No Okay, let me go ahead and reload this copy that and reload it is stuck on my last Stuck on my last Tutorial and as it goes back to this setup, I'll fix that in a minute basically here how I've got 85 90 and 100 so this looks very much so far like What we have in Java, which is nice. It makes the transition a little bit easier But again, there are some significant differences as as you'll see here in a minute And we go ahead and change the text size Too large for that. Okay And I get it back to where it was. All right, so Now one thing though is if I had done this I Hadn't put three zeros in there. I'm gonna get an error. Let's see what happens Okay, so you see where it says list assignment index out of range. So there is no zero here There's no zero element one element or Element two there's absolutely nothing. It's empty Okay, so like an array list what I could have done is I could do this now Dot Add I think it's add. I haven't done this for a while actually Let's try it 90 and I'm probably getting it backwards. Let's see what happens Yep, it's a ad is for Java a pinned is for Python Go ahead and run that and hopefully we'll see run that too There's no add. I know we're waiting. I'm not sure if it's my internet slow or they're slow today It could be a combination of both. Okay, so we got 85 90 So that was basically the same thing as we had was score zero equals 85 And what this does a pen just is just like with an array list Add in Java it adds it to the end could not find class main. Oh It should be main. There we go. That's where we went wrong. I think when I originally did this tutorial I didn't do it and replete. I did it in something else So I just copy the code here. I should have tested that first my apologies Okay, there we go. So this is this is what we want so you can see here. We've got the same scores Let's go ahead and do the printing like we have there now again back to our loops And we're gonna use for I in range And we're starting at zero and we're going to the length of scores Of course minus one it automatically increments colon. We tabbed over four spaces print Score and space And what I'm gonna do is I'm gonna go ahead and use format colon So dot format So I want to use I and then scores I Again, this is just building on everything. We've looked at so far So we should see score 0 85 score 190 score 100. So yeah, same thing same concepts Just done a little bit differently. Okay, and let's take a look here now. We want to calculate the average So I want to go ahead and do that again. We don't need the double. It's again. It's called a float in Python Here we've got camel casing. We're gonna use snake casing average score equals I'm gonna say scores in this case. It's the exact same code basically. I'm just gonna go ahead and copy that It's gonna be lazy That's nice. It's where you can eat that one of those rare cases where you can actually just copy and paste and it works Don't need the semi colon and I'm gonna go ahead and print Average score colon and don't forget the braces dot format average score And hopefully we will get the same result 91.6 repeating Okay, and interestingly it is the exact same There's a few but it looks about the same length. So interesting. Okay. Now. Let's go ahead and move on try a few different things here so In this example, we've we've pre-populated our array with some Data we can do the exact same thing here heights equals 150 160 170 and 180 That's a common on a dot. No semi colon These brackets here these square brackets. They tell you that this is a list And so it's it's just obvious from that that, you know, this is a list type Yeah, so let's go ahead and do the same thing So we say 4i in range Again, we're starting at zero going to the length of heights Incrementing by one because we want to do all of them print heights And just be able to basically just doing the same thing here and again the difference between this example and this example was here We started with an empty list and appended here. We're starting with a pre-populated list Do that And this is exactly the same thing. We just did format I and Heights Let's go ahead and run it make sure it's working Fantastic, I forgot to put a little print statement there. All right moving on Using the for each method. I can do like this for height in heights and I strongly strongly strongly recommend this to my students that any time you make a list That the variable name should be plural Okay, this will help you to write I think easier to maintain an easier to understand code and then when you do something like this It just makes logical sense for each height in heights We can go ahead and print It's go ahead and test that and there we go Okay, moving on Okay, so same thing here We could do something weird got disconnected So average height equals blah blah blah blah Things do I need to do that? Okay, tell me why don't we do this a little bit differently since it's really just a repeat of what we did up there Or I guess I could copy it but what I might want to do is I might want to say total equals zero for height in heights total plus equals height and Then I will say the average height Again, can't snake casing equals total divided by the length of heights So if we got four heights and then we'll go ahead and print average height Brackets and format Average height You can see I'll just you know good good variable naming just makes your code easier to read and to understand Let's see if we get 165 and that is what we wanted and what's nice about this method is if we go ahead and added somebody We added 190 centimeter person and then the average is automatically updated everything is printed out as is so you can see there's kind of a few similarities between how arrays work and How array lists and lists in Python work So I'd say basically over all that lists are a lot more like array lists in Python or in Java So it's probably a bit more of a better comparison, but I just want to point out that there isn't really a difference in Python between lists and Arrays an array list there. It's basically arrays an array list lap wrap up a one But one thing I do want to show you is And you can't do this in in Java I could say I could say I'm just gonna say stuff Say hmm That's a stuff. It's okay. That's not a plural equals zero 2.2 Bob and True So you see here, we've got four different types of things for thing in stuff Print thing Let's see what happens Okay, so you can see how it just went ahead and print them out so one thing that you'll see here in Python is that lists can have multiple different types of Values in whereas in Java particularly in arrays. You don't see that at all again, remember arrays are limited to primitives for the most part and Array lists will allow you to do objects Actually, no our arrays limited to Primitives not to check that one out. I forget now. Anywho, so yeah, that's kind of an interesting one So something to think about okay Moving right along. Hope to see you the next one. Take care