 What's going on guys root of the now here coming back at you with another Python tutorial. Let's get idle fired up Let's see what we can do here now before I jump into a new script or a new program I'm gonna say in the interactive shell and show you what we're working with today And then we can go create a new file and do our own thing But now we'll be looking at list list data types They're a lot like arrays in fact arrays into their name for them But it's really the idea of holding multiple values inside one Variable where you can index things with numbers and retrieve information back and forth and that sort of thing now I remember these are denoted with these two braces or these two brackets and for me. I'm just gonna set up one that is a An ascending integer Array so we get one two three four five and I'm actually going to set this to be a vowel a variable here array can equal One two three four five so now if we check out array We have obviously one two three four five and the function we're going to be looking at today is called reverse Now if we type in our variable name and use our dot selector if you do control space You can see all of these functions that we could be running with and in our case We're gonna check out reverse so let's type in our two parentheses And if we do control backslash inside those parentheses you can see the variables and the values They're gonna have to pass in for arguments now in our case We're kind of lucky reverse doesn't take any arguments, but what it will do is it will reverse the array So if we run this we don't get in the output because it's not returning anything to us because this function doesn't return anything instead It really does a modify the original array. So if we look at it right now, we have five four three two one Now I myself don't like this. I don't like it when the functions actually manipulate the real variable So I'm just gonna have it return to us when we when we try and create it today But obviously you can set this up if you'd like you can go into more in-depth research and try and figure out How to do this, but I don't like to and I don't think it's I don't think it's something we should even bother looking at But hey, let's try and take a look at this all on our own because see remember We're taking a look at one two three four and five and we're reversing it So in our case five takes position of one Four will take the position of two and three will take the position of where it's at because array has an odd number of elements or items inside of it So let's try and create this. It's a pretty simple function, but it looks like it might get a little bit tedious Let's try it though. Let's create a new script here. I'm gonna call mine file dot Python Get a new shebang line started Create a class We don't need these comments here, but I do because that's just my personal programmer style to find a constructor the init keyword wrapped in two underscores Both on either end passing yourself keyword as always because you should always do that when you're um When you're creating a function inside of a class if name is equal to main now outside Outside the class in our global scope We can do a conditional statement and test if this is the current script that we're running And if it is we can create an instance of our base class and call it roots now everything inside the constructor will happen Automatically because that's just what happens with constructors whenever you initialize an object like root in our case It'll run everything inside the constructor. So let's create our array variable. Let's do array and Now it remember it's a list. So we have one two three four and five Now if we print out array, I'm going to concatenate some new lines on here. So we have to turn this into a string and add on new line new line just so we see what we're working with here and we get one two three four five So if we now run a array reverse We run this nothing's gonna happen and even if we printed something out here It'll tell us none because that function doesn't return anything all it does is modify the original variable like I was saying So we don't have to print anything out here We can just run the function But then we should take a look at our array variable and I'm not gonna concatenate anything on here So we don't have to convert this in with a string data type. We run this we get five four three two one It's gone in reverse now. So let's try and create this all on our own. I'm going to remove these lines here and Define a new function outside of our constructor. I'm gonna call mine reverse We need to pass in the self-cured as always and then we're going to need obviously the array that we're gonna be reversing So now we need the array length So we can loop through the thing with an index so a re-length It's gonna be an integer data type integer data type and then we can use the le end function to get the length of any object So we'll pass in the array here And then we can we can begin to loop through it. So for I in The range If I can type in correctly, holy crap for I in range and then a re-length So it'll count up until the length of the array here And now what we're gonna do is we're gonna add what we find into a new array So before we loop we can set up a new array and that's gonna be blank for now And now a new array can equal array Remember what we're adding should be in a new array can plus equal because we're adding on to it We're appending new array can equal a List data type so we have to have our our braces around it our brackets and now you can use a ray Pass in with I Now when we're done here, we can return when we're outside of our loop we can return the new array that we've gotten So let's take a look at what we're building here. We have successfully Loops through the list though with an I variable that's going to index and what's gonna increment each through each number Or each element inside the list and it's going to index each thing So we're gonna start at zero because that's what the range function does when you don't pass anything into it And it'll do I zero Let's see I 1 2 3 4 Now the thing is we're trying to count backwards though So if we're adding a new array, we aren't reversing anything here all we're just doing is adding it all together So what we should do though is try and turn this into the negative value So that way we can count backwards because negative 1 is 5 negative 2 is 4 negative 3 is 3 negative 4 is 2 negative 5 is 1 So let's let's give this a go. Let's see what'll happen here. Let's print out Print out a self reverse remember you have to use your self keyword because the function is inside our class here We can pass an array and then we're done now we get one five four three two Whoa, whoa, whoa. This is a little weird right one is that that first index Right, so it should be over at the end not at the front. We get five four three two That's in the right order, but one is just out of the blue here Now remember this is because One is at index zero and when we do that if we do negative zero it's still going to return zero So a new array plus equals zero. I'm sorry array zero is going to have one So we get one five four three two what we have to do is make up for this one variable So what we can do is we can start counting from one at a railing and then we're done We can add on and we're done looping anyway We can do new array plus equals the array value or the list value of array index with zero So now when we run this we get five four three two one because we've started counting at negative one Oh, sorry, we've we started counting at one, but when we add this to an array We're looking at that negative value. So we get negative one negative two negative three negative four negative five except we're not getting that because it's a part of this less than that length here and Now we can add on that final piece here that array zero so essentially we're turning this all Reverse and then we're adding on that bit that we would have missed So now you can see we have five four three two one now There's a lot of interesting things you can do with this function if you wanted to you could potentially set up a start and end For when you're reversing and that sort of thing Yeah, you could decide if you want to reverse more elements and just then just one section that sort of thing But knowing how this works is going to be crucial for your understanding of when you might want to use this function That sort of thing, but hey, thank you guys for watching. I hope you enjoyed this. I know this one was a little bit It's interesting I mean you're indexing with a negative value and you have to make up for the fact that you have one That's just sort of extraneous and out there, but hey, I hope you guys enjoyed this Thank you for watching. Thank you for listening and I will see you in the next tutorial