 Hey, what's going on guys? Rudolinal here, and we're coming back with some more Python tutorials Let's fire up idle and see what we can do here. We create a new window as always File.python. Alright, so now let's create ourselves a string variable. I'm gonna set this up as self.string called this This is a joke All right. Now the function that we're gonna be looking at today is called ljust So if we try it self.string.ljust And we pass in Let's see it Actually, let's try it in the interactive shell so we can see more of what's going on here. Let's set up a string variable This is a joke. And now I've got string.ljust And what ljust does is it left justifies. That's kind of why it's called ljust So if we control backspace, well control backslash, sorry, to take a look at our functions Take a look at the parameters that we're gonna need here We have width which is a mandatory parameter if we run this it'll give us a problem without it So and that's going to be an integer for how long it should be and then we have a fill character and a character And that looks like that's optional because the space character is the default So if we just type in maybe five for a width, it's not going to do anything because the string is already greater than five So let's try something like a big thing. Let's try a 30 This is a joke and now you can see that it continues onward right after the string up until it gets the quotation mark Because that means it's the end of the string and all this has been justified So all that space characters are set there because that's what you should do now You can change this to a fill character, of course We can set up a plus sign and now we get all these and that's going to have the width in total be 30 I'm curious whether we could add multiple Nope, it has to be a character and not just a string So we have to have a plus sign or anything that's only one character long. So let's give the go Let's try and recreate this function all on our own first of all Let's change this to a 30 so we can see what we're doing here in our script If we run this we get this is a joke and then all this here is See if we can select it all up until that point where the cursor stops is the string So let's try and recreate this. Let's do define Left justify We'll pass in self and then string to Justify so now what we do is we're going to need oh we also need the width and then we need fill care and Actually, we should change this to spacebar, okay, so now if fill character actually if the type of fill character is Is not a character or CHR I'm thinking that should work. Let's try it. I haven't tested this idea yet But it'll definitely it's always worth an experiment if the type of fill character is not a character then we can just do Fill character equals character version of Fill character Space that out just a little bit and what I'm going to do here Just for a little bit of debugging or troubleshooting is print out the fill character so we can Run self dot left justify We can pass in self dot string even though we're not going to be doing anything with it right now It set up a width to be 30 and then fill character which by default is a space an integer is required Okay, so that's not going to work So what we can do here instead is if the length The fill character is greater than one We should set fill character to be equal to the fill character with the index of zero or whatever is at that first position So if we print it out, this is a joke We print it out this spacebar here and we can change this to let's say plus sign And now that works, but what if we change it to a plus sign the period in there in the quotation mark? I'm sorry a question mark We change this it's going to not throw an error at us like the self dot string dot L just function does but instead it will take only that first plus sign So if we run this we get that single plus sign So we've kind of avoided an error here when we built our own function and that makes things a little bit easier I suppose it depends on how you want to be programming, but anyway, let's give it a go here Let's do we're going to need an integer. So We want difference and that can be the length of the string to justify and Then we're going to want width minus that So now we can do return let's see string to justify and We can add on the fill character Repeated by the time by the number of differences we have So now if we print this out, we're going to get this is a joke and then we've added a plus sign So now if we run this up with the top one And we use our plus sign. Oh This is a joke L string that justify That's right. We have to have it inside the L just function. I'm sorry not the print function and Then we need our plus sign This is a joke with all these here and then this is a joke with all these here So we have that we have the same number plus signs here So we find out the difference and then we multiply that character Times that difference that we find and we add on the string that we're justifying to begin with So here we are if we don't run this if we don't put in that fill character But instead we print out Don't print anything else. We've already got our print function here But if we add a quotation mark and another one we can concatenate these on We can see exactly how long these strings are We run this This is a joke and this is a joke and we even have these left justified spaces here So this is exactly what we wanted it does the exact same thing or at least what we think of the exact same thing We have the same output as the original built-in function. It's simple It's easy and all it took is a little bit of math Not much any math not much math anyway And then we kind of avoided the error with our little fill character thing and we could test if it's greater than one character If it is we'll switch it to only being one character. So we're done guys Thank you for listening. I hope this made some sense And I'll see you in the next tutorial. Yeah. Bye