 Hey, what's going on guys? Root from NullShell.com here with you guys again today, and we're looking at some more Python code. Let's fire up idle and see what we can do here. I'm going to create a new window, save this as file.python. Let's get our shebang line started, usrbin, environment, Python, and now we can do class, classbase. We can define a constructor here, pass in self. Now we can test if this is the current script that we are running. So if name is equal to main, and if it is, we can create a root object, which is an instance of the base class. Alright, now open our class. Let's create a new variable. It's going to be a string variable. We can set this to, you know, this is a new string. Let's get some tab characters on the end here, maybe a space in a new line character, and that's all we're going to need for now. So now let's take a look at what we're going to be talking about in this video. If you guys remember, one of the functions that we were looking at earlier was a lstrip, or leftstrip, and what this function would do is it would strip all the white space characters by default on the left side of your string. So if we tried the self.string.lstrip, first of all, let's print out the regular string, self.string, and look and catenate on some new line characters here. If we run this, we get this is a new string, and then we have this is a new string over here, but we want to put in some white space characters. Let's put in all these tab keys and white space. So if we have it the first time, we have all these characters here because that's what we've put in. But, and we run it with the lstrip function, it removes all those white space characters by default at the front of our string. But we can also pass in some characters that it would remove as well. We can set up maybe a tab character, maybe spaces, and maybe T. So we'll remove that first capital T up at the top here. Then we can set in I, and there we go again. But you can see you kind of expected it to remove that I that's inside of this keyword, wouldn't you? The thing is, because that H is in the way and H isn't in that character, that character list that it's going to be removing, it's just going to stop and it's going to forget about that I because it doesn't even see it. So let's try this again though. The function we're going to be looking at today is called rstrip. rstrip is a lot like lstrip, but it works at the opposite end, at the reverse side. You could use r for reverse, or maybe you might just think of it as right, because what it does, it removes all the white space from the right-hand side of the string. So in our case, it'll take the space characters, the tab character, and that new line character, and of course we can pass in some other things we might want it to do. So let's pass in those new line characters. Well first of all, let's do it without anything. We run it, and there's nothing on that end here. Let's see at the top string, there would be, but there's nothing here. So we can try this here as we can pass in spaces, a tab key, a new line, and maybe an exclamation point. So now to remove that last exclamation point on the end here. We could pass in, maybe we could pass in a G. That works, and we could pass in an I. But it doesn't remove that I, because the end is in the way, remember. So what if we change an N here? Now it takes all of them. So you see what I mean? You see what I'm getting at here? So let's try and recreate this rstrip function, and make it our own. So let's define a new function. I'm going to call mine a rightstrip. Pass in self. We're going to need a string to look through. Then we need the characters. And remember, characters is an optional parameter, so we're going to set this to none by default. But when we're running the function, we're going to want to test if characters is still equal to none. If they haven't supplied anything, then we should supply something all on our own. So what we'll do is we'll set characters equal to a new module, so string in our case, and then whitespace. So we're using the string module, so what we're going to have to do is import it right up here at the top of our script. So we can import string. And now we'll be looking through all the tab keys, all the new line characters, all the spaces. And that's going to be what we're looking for. So now let's go ahead and actually get to writing this though. We're going to need a new string variable, because remember we can't assign strings, so we're going to have to create a new one all by ourselves. And this will be blank for now, and we need the string length, or the length of what we're looking through. So string length can equal the length of a string to look through. And obviously we don't need a code block here. So what we're going to want to do is count through the string, except the thing is we're going to count through it from the reverse way. So we're going to have to index with like negative one, negative two, and negative numbers, so we're able to check from the back and keep going, that sort of thing. So we can't start counting with zero, we have to start with one, because if we're going to be passing our incrementer as an index variable, we're going to have to set it up though it starts at one and we go through negative one, and that sort of thing. So let's do it. Let's do four i in range, and we can do i and then string length, actually one, sorry, because remember we're starting at one, we're starting counting at one, and we go up until the end of the string. And now what we're going to do is while we're looping through it, we can test if string to look through, while we're looking through it, we can send in our index here, negative i, and if the character that we find is in the characters that we're going to remove, what we can do is set new string, and we can plus equal nothing. So we're not really doing anything to it, and in fact we probably don't even need this if conditional statement, but it's a good idea to have just so we know exactly what we're doing. But if not, we can break out of this loop. So now we're starting from the back end and looking for things that we would find, and if we find anything, we don't have to worry about it. So if not, we can just break. And now that we're done that for loop, we should try and create a new one here so we can get the rest of the characters that we'd be looking at. So let's do four k, and we're going to do four k in range i, because we're going to start off from white where we left off, so i, and then go until string length, and we can start our code block here, and we can do new string, it can be equals string to look through, negative k, index with negative k, and then we can add on the new string. So this is going to build the string from the reverse way. If we did new string plus equals string to look through, it'll take like the current one and then add to it again. But since we're counting in the reverse way, we have to actually add to it the reverse way. So what we do is we take the current character, and then we've had previously, the next character, and then we've had previously, the next character, and then we've had previously, because remember we're counting backwards with this negative index here. So now that we're done with that loop, what we can do is set up the ending of the string. Because we've started counting from that one, we're going to miss the first character inside that string. So what we have to do is type in new string and add it to string to look through and the first character here, and then we add on the new string. Now when we're done, we can finally return the new string, because now we've finally completed it and we've completely just regarded anything that was in the characters. So now we can go back up to our constructor, because it looks like our function here is complete, and we can actually build what we were hoping for. So we can do print self.string, actually self.writeStrip, because remember we're going to have to pass the string into it as a variable. Now we can pass in self.string, and we don't need to supply any characters at the moment, but let's save this and let's run it. Oh, I have an error. If characters is equal to, remember to use your comparison operator here, run this again, and now we have this is a new string with all the white space removed for both functions. You can't put your cursor anywhere after here, but if you go up to the top one, you can. There's all this here. So now that it's looking at white space by default, let's try passing in some other things. Let's pass in this one here, and let's send over along with the same thing here that we were looking at earlier. I'm going to copy and paste this one more time. Let's put it right in here. That's going to get, this is a new straw, and this is a new straw, because we've removed the G and the I and the N, because we've been looking through it through reverse. So now what we can do is actually try and clean up this if conditional statement here, because the new string isn't actually doing anything, if we're appending on nothing, we're not really changing it whatsoever. So what we can do, we're only testing is if we find something that's the opposite case. So else, what we can do is remove all of this and do not, and then we can break if we find something that isn't in there. Let's try running this now. We get the exact same output because we're doing a different thing here. Let's put R in here. R, R, and now we remove that ST. But all we've done is eliminated or sort of cleaned up that if statement a little bit, and we don't have to worry about adding nothing onto the new string, because if you're adding nothing, you're not really making any change. So we've just cleaned up our code a little bit. We've recreated a function that could be very handy. And yeah, I think we're in a good spot here, ladies and gentlemen. So thank you guys for watching. Thank you for listening. I hope you were able to understand this. I hope you're able to comprehend it, especially the little bit here at the end, because I did sort of do a little strange thing with that if statement there. But you know, we cleaned it up and we made it exactly what we wanted it to be. And yeah, we should be set. It'd be nice if you guys could leave me a comment. Maybe I'll like the video if you'd like and subscribe. But hey, it's all you're doing. I am not going to force you into doing anything you don't want to do. But if you want to see some more things from me, I'd definitely recommend it. It gives me a good idea of what you guys like and what you guys want to hear from, and that sort of thing. So thanks again, guys, and I'll see you in the next tutorial. Bye.