 Hey, what's going on guys? Root of the Null here, coming back at you with another Python tutorial. I'm going to get idle started up, and then we can get to program and save your script as whatever you'd like. I'm going to call mine file.python, type in our shebang line here, create a new class, define our constructor with the def keyword along with the init keyword wrapped in two underscores on either end, go down and create an if statement, and now we create a new object, and then we should be set to go. All right, so I'm going to create a list variable here, just like we have in the last couple of videos. I'm going to call mine self.list, and the value can be this is a list. And now we can print this out, we can print out self.list, and I'm going to concatenate on some new line characters, obviously you don't have to, but if we do do that, we have to convert it into a string. So if we run this, we get this is a list, and then we get those new line characters that we have been asking for. So now let's take a look at today's function, or the function that we're looking at in this video. It's called index, and now what index would do anyway is it would return the first occurrence in the number of elements inside your array or your list, and it would return the first occurrence of whatever you pass to it. So if we go ahead and print out self.list, and we use our dot selector to run the index function, what it will do is it will pass in is, I'm sorry we can pass in is, and it will return one, because one is the first index where it finds that value. So because if we're starting counting from zero remember, this is zero, is is one, a is two, and list is three. So we actually have a length for this for this list to be four, because we have four elements, but is is going to be found at the first index. So let's run this, and we can see we found one. Now we can supply a start variable too, because it's an optional parameter, we can supply let's say we wanted to start from the first position. We still get one because we started looking right there, and we can also, what if we started somewhere after this? If we do this, we get a value, or at least a value error, because is is not in that list. Because if we start checking from two, we have a and then list, but is isn't in there. So it's going to return to us an error. Is is not in this list. So when we're creating the function all by ourselves, we can decide whether or not we want to return an error, or we can actually just return zero that we, or like a negative one that we didn't find the thing. So let's give it a go. Remember, before we jump into the action though, we can supply an ending variable. If we wanted to start from zero and end at one, we could still get this because we're going from zero to one, except we're not going to count one because it's at the end. While zero is less than one, zero is only going to be zero if it's less than one. So we have this, and what's not going to find is. So let's try and recreate this. So let's go define our own function, define, I'm going to call mine index, passing the self variable, we're going to need the array or the list that we're looking for, I'm just call it list, I suppose. Actually, if it's going to highlight it, we should call it array. And then we're going to need the value that we're looking for, we're going to need start, which could be zero, and then end, which can be none. Now, the reason we're setting end to be none is because we're going to want to change it if they haven't supplied it. So we can test if end is still equal to none by the time we're running our function. What we can do is change it to end, which is going to be the length of the array that we're looking at. And now we can begin to loop. So we can do for I in range, because we're going to count through this, we're going to want to start from the start variable, obviously, and go until the end. And then inside of that code block, we can test if array I, so the current variable we're looking at is equal to value, or at least what we find, what we can do is we can return I. So remember, the return function will break out if anything that we're in, so we'll break out of this if statement, we'll break out of this for loop, and we'll break out of the function. And we'll just go ahead and return back to the scope above us that, okay, we found it at position I. And now we should be set. But remember, if it doesn't find it, for now we can return negative one, because we have not found it. So let's try this up in our constructor. If we print out self.index, and we pass in our self.list, and we'll look for the is. If we run this, we get one, because remember it's at position one. If we go ahead and run this along with the original function that we had, we both get one in both cases. Now let's pass in, maybe we can start from two. We can start from two here. But remember, we're going to get an error. So we can't really work with this without commenting out the first one. If we start from two, we get negative one in our function. But we should, I suppose, change this to the value error if you guys want to have like the real pristine recreation of the original function. So let's work with that in a little bit. But first we'll go back to zero and one. And remember, it's not going to find anything anymore either, because we're still checking this one. But if we went from zero to maybe three, it's going to find is at that first position again. So now let's go back inside of our function and see if we can set up that value error. Now the way that we would do, that we would raise an error inside Python is called the, at least you can initiate this with the raise keyword, R-A-I-S-E. And now we can raise the sort of error that we want. And in our case, it is a value error. And then we can pass in inside parentheses here what we want to be displayed. It looks like they were using is, so that value and then is not in the list. So we can do this all by ourselves. We can do I, I'm sorry, not an I, but a quotation mark. And we can add on the value. And then we can add on the quotation mark again. And then we can just say is not in list. So now, if we run, if we run this, oh, it looks like there's an error. We did not concatenate this on. I forgot my addition sign, sorry. And now we get the value error is, is not in the list because we started counting, well, actually that's the first function. But if we, if we comment that one out, and we start from two, it's going to give us that same output because it's not in the list. So we get this one up here is not in list, and the same here is not in list inside of our own function. So we've kind of practically recreated the original function. Now, remember, you can pass in the end argument as well. And you know, there's a lot we can do with this, we can help actually look for where we find something inside of our string outside of our list anyway. And we can obviously change the value that we're looking for and that sort of thing. And we could have this become a more versatile function, especially if we work around that error, that error handling and that sort of thing, because we can always have it return negative one if we don't find anything else. But before I, before I go, I want to show you guys an interesting little commenting tricks. If we have a quotation mark here, at least a multi-line comment, and then we have a single line comment, and then we have more, if we end that multi-line comment and we add a line here, we can toggle a quote from this ending comment to run code below. And now if we wanted to use our return function, we could set this up in that same style. And then I'm going to copy and paste this, make it easy. And then at the, at least under that, we should set up those same one, two, three, and then that one here. So now if you actually look at the description here, if you toggle a quote from this ending comment to run the code below, what we can do is we can remove one comment from here, at least one quote, and now raise has commented out. But return is still running. If we just, if we had it the other way around, we could just toggle this one and put this one back on. And now return has commented out, but raise will run. So we can quickly alternate between which function that we want to run and everything stays easy. We could run that one, we could run this one, we could just cut this one out, and that sort of thing. So you can quickly decide which command or at least which statement you would prefer to run, depending on whether you're like, you're debugging your code, you're trying to troubleshoot a problem or that sort of thing. And you have to alternate between one statement to be able to see what the output is going to be. But there you go guys. Here's our, here's our function for today. And here's a little bit of a commenting trick. So I hope you guys enjoyed this video and I will see you in the next tutorial.