 Hey, what's going on guys? Root of the Nell here coming back at you with another Python tutorial. Let's get idle fired up here and let's see what we can do. We need to create a new window. Save this as, let's see, file.python. We can get a shebangline started up. Begin a class, base, define a constructor. Passing the self keyword as always. Let's create if the name is equal to the main. We can create a new object, root equals base, and now we can get started. Let's create a new string variable. Self.string equals, this is a string. It is, isn't it? And that can be a string variable. So now the function that I want to talk to you guys about today is something called rfind. And this is a lot like that function we were looking at in an earlier video called find. And what it does is it will find the current position, or at least the first position, of a substring that you pass into your function. So rfind does this in the exact opposite way. It will start looking at the, from the end of the string and going down. So rather than looking for, if we type this out, let's do print self.string and then we can do find. And if we, if we passed in is, it's going to start looking t, h, i, s. Oh, it's going to find is at that second position right here. It would return that, but if we supplied rfind, what it does, it'll start looking from the end. So we have a question mark, ti, spaces, and then, oh, there's an is right there. So it would return whatever position is right there rather than something over here. So we can try and recreate this all on our own. If we did that same thing and we printed out a function that we created that does this. So let's try and, let's try and get started. Let's do define, and then I'm going to call mine right find, because that's all it really is. I'm going to pass itself as always. We need the string variable. Substring is what we're looking for. And then we can have start, which is going to be zero, because remember we had some optional arguments in the find function. And that goes the same way for the rfind function, too. We have a start, and we have an end. End equals none, and we can create a code block here. So when we did last time, we tested if end is equal to none, if we haven't supplied any argument for that, we're just going to set end to be equal to the length of the string. And now we need the substring length, too. So let's do substring length. We can set this to a new variable. It's going to be the length function, or the len function. We'll just pass in substring, or what we're looking for. And position is going to be a variable where we save the current position. Since we haven't found anything, we're going to set it up to be negative one. Just remember, if we ran find, and it's something that we didn't find, like a z, it'll return negative one. So we're going to set that up for position for now. And that's subject to change while we're looping through it. So let's try it out with is. We'll at least put that back in there, and we can get back to our function here. What we're going to do is we're going to loop through it, as always. We're going to count with numbers, too. So we're going to use for i in range. Then we can go from start to end. Get our code block started. And now we can test if the string, and from the current position, we can slice on here. Then we can do i plus substring length. So the length of what we're looking for. And if that equals the substring, if we found the string, then we can do position equals i. So now it'll keep resetting the position for every time it finds something. And if once we get to the end and it's found this last one, what we're going to want to do is anyway return the position. So when we're done looping, we'll have the last position that we found. So it's going through all this, but it's going to retrieve this one here because it's the last one that we found. The effect of going through this way, though, and it finds this one first off by looping through all of this at once. So let's try it out here. Let's go f5, and we get 25 because we're running the original function here. So let's chain this to, at least let's put an R function here. Let's do print, and I'm going to put mine at the bottom. Print self.rightfind, and then we can pass in self.string. We're going to look for is, and that's all for now. We get 25 and 25 because we found 25, or at least the last is, is that position right here, and that's going to be the 25th character, that 25th position. So if we pass in another argument so we know where to start from, we can just say like 3, actually 4, that works for me. We can pass it in an R function too. We can set up 4, and this is still going to return 25 because we're only counting at the fourth position. So we're still going all the way through here. But if we do maybe 26, what we're going to do is get a negative 1 because we're starting right above this is. We haven't found it. So what if we did it at maybe 1, or 2, that works. We can do 2 again, and we'd still return 25 because it's the last one. But if we did, let's say the last one can be 20. Yeah, just play no 20. 2, and then the N can be 20. It's going to return 5 because it's going through position 2, and then it's going all the way up until it gets to 20. So now this would be the 21st, this I right here, that second is, so if we go from all the way up to here, the next is that we find is that position 5 right here. So that's why we return 5 because we're going through this way. But it's going to return the last one that we find, so it looks like we're working from the end. And that's how it works. This small function here, it's just the same as the find function, but with a little bit of modification, you're understanding this position variable, and that's what's constantly getting updated every time we find something, and when we're done looping through the string, we can return what we found, or the position of the last string that we found. So that's how it goes. Thank you for watching, guys. I hope you enjoyed this. I know this one was a little bit simple, and it's very similar to what we were doing beforehand, but it's just a new idea of being able to store what we just recently found in a variable and then return it when we're done looping. So yeah, it'd be nice if you guys could like the video, maybe leave me a comment, tell me what you think, and maybe subscribe. I don't know, it's just an idea. But I'll see you guys again in the next tutorial. Goodbye.