 Hey, what's going on guys RudeLinLinL here coming back at you with some more Python tutorials Let's fire up idle and see what we can do here. I'm gonna create a new script file.pythons Type in a shebang line if you're on linux create a new class There's a Create a constructor. I can test if this is the current script Had a random parentheses in there. We're gonna fix that Let's create a root object. There's an instance of our base class Now let's create a string variable here up inside the base class Let's create a self.string and we can set this to Tab tab some spaces in here. This is a new string Okay, so now let's take a look at the function that we're gonna be examining today This is something called lstrip and what lstrip does is it removes all the white space characters? Inside of your string That are at the front that are at the far the far this left position of your string So what we can do here is is try and test that out. Let's print out self.string.lstrip I'm gonna run this it says this is a new string, but if we had printed it out regularly self.string It displays the tab keys and a couple spaces. This is a new string So what self string.lstrip does is by default will Remove it the white space characters, but you could of course change this to be anything else as well Maybe we could change it to like any characters like q, r, z, and q, r, z, and s, q, r, s, and z in our case if you want to go in order And that isn't going to remove anything But if we had just some random q, r, z, w and that sort of thing It'll remove none of those because at the beginning you see there's this q here And that's not in our list of characters to remove so what if we move this q over to let's say the end of that string We only get this q here And it's removed the r and the z and the s and the w because those are in the character list That we're trying to get rid of but the q is going to go away What if we added a backslash t in there to see if it will remove the tabs and it will but it still has those spaces to work with So let's try and recreate this all on our own What we're going to do here is to find a new function. We're going to call this left strip and We're going to need self and the string and then characters We can change this to be None first of all And we can test if Characters is equal to none We're going to want to change this to an ASCII thing here. So let's go ahead and import our string module And we'll change it to anything that is white space Characters can equal String and we should change the string that we're passing in remember to string to look through Characters equal string and then we can change this to white space right here Great. So now when we loop through a string to look through we can do for Character in string to look through we can test if the character is in characters And if it is We can we can remove them and the way we would remove them is once again creating a new string variable for so we can do new string Create this here and then if it's in the new string characters Let's see Hmm. Let's try and see how we can do this because if we continue to loop through this and if we set new string Plus equals nothing That'll that'll remove all those characters all those white space characters And then if we did else and we added the character It'll remove things that aren't at the front of the string though So we have to try and accommodate for this and I'm thinking we could do this by counting because if we did this String plus equals character if we had ran that when we're done we return this new string if we print out That's a self dot left strip You can do self dot string here. We can run this and New string reference before assignment. Oh We should set that to be nothing first of all I'm gonna get rid of this this one right here See what this does it'll get through all the white space characters But even if there are white space characters Inside it it'll still remove them because we have these spaces here and we're removing them because we're only because what's only It's going through the entire string and we don't want that we only want that that first one So what we can do here is I'm assuming create a new counting loop. Let's try and comment this out and Let's see if we can try and invent a new logic structure here Let's do the let's get the length of the string can be the length of What we're looking for string to look through and we don't need a code block there That's just absurd. So we can now we can loop through that one. So for I in range of string length What we can do here is test if the character is In characters is in that thing that we're trying to get rid of or that risk the list that we're trying to get rid of We can we don't have to add anything to that string Plus equals nothing, but if not, then we know that okay something is wrong here. So let's do else, let's see We can break out of this loop though And we're gonna want to keep I though because I is gonna let us know where to begin from the next loop But we're gonna want to loop another time. So for K in range I in The string length and then we can add all those things that we would have missed So new string can add character or I'm sorry string to look through With the index of K. So let's give this a go Global name character is not defined. I see I'm sorry if string to look through Because remember we're using I to index now. We aren't using we aren't using character as a placeholder So string to look through an I and if that's in the characters, we can add something to it So now what this has done as it's removed all the white space It's in the front of the string here and this works perfectly because we haven't supplied a string Characters list to look through though But we're going to get the white space string that ASCII has applied for us So if we do import string in the interactive shell We do string dot white space All the things that are in here are going to be removed by default with our new function left strip But all these other things even if it's in there after it. It's going to be Removed so let's try adding a so adding a I think a parameter here left strip and then anything that's in our new qwrz s and Then a tab key and let's leave the spaces though Let's create a couple more here and then let's do SR WQZ and then a couple more Z's maybe an S in there and then we can run this and It has all these but inside of our string that we've passed to it It still only has the spaces because what we've done is we've looped through at once And when we've tried to get things that are inside that character list if it finds them It will remove them by adding nothing to the string character But we're still continuing that loop or at least that position with I and then if we find something that isn't part of the characters We will break out of this loop and continue to go from another loop Starting at that same position where we left off as and then we'll add all the characters that we found So this is going to let us let's see add to it in a different way So that it'll only remove the things that are in the front of the string or at that leftmost position And that's how you set things up. So let's try it with the let's try with the real string Let's concatenate on here a new line Couple new lines so we can see what the original is and then what the built-in function will do and that sort of thing. So let's do We set up QW RZS. If we run this They both display that same thing So there you go guys look at what we've created here This is going to allow us to remove white space or any other characters that we supply inside our strings And we've built this and took a look at the function in our own way And now we've gotten to something a little bit more advanced so you can be proud of yourself But thank you guys for watching. Thank you for sticking with me. I know this one is a little bit more of an adventure But hey, I'll see you guys in the next tutorial. Bye