 Hey, what's going on guys? Rilinel here, coming back at you with another Python tutorial. Holy crap, how many we got here? I don't know. Anyway, today we're going to be looking at another string function. We're going to check out string.center. Now remember, we're using our dot selector here and you're looking at the string data type. So you're really just centering a string. We're going to be checking it out and trying to recreate it as our own. And then we're going to import a new module, import math. So it's going to be your first time taking a look with more module-based stuff. So let's get idle ready and we can get started. I'm going to save this as file.python. Actually, I don't know. Should I call this something else? I'm thinking grandma. Grandmother Python. Yeah, that sounds good to me. Whatever. User bin, environment Python. Let's get a class going here. Base define in itself. Get some code blocks. We can actually set a string variable, self.string. This is a string. Oh, what are we doing here, idle? All right, so now we're going to do a conditional statement if names equal to main with roots, not fruit. Fruit is our base object. All right, now, let's get started here. Let's take a look at what we can do, first of all. We can do self.string. And then dot center is the function that we're going to be looking at. And now what it would do is you would take in an argument for like the width or how much of it you want it to be centered. So let's just try like 40. If we print this out, we'll be able to take a look at what we're trying to recreate here. So this is a string. What if we tried it with quotations? So I can show you how much it is centered. We're going to get some single quotation marks here, concatenate that on. We can concatenate another single quotation set. So we have a quotation mark here and then a quotation mark over here. And it's separated by all this white space. So what we've done is we've centered the string that we took as an argument and put it in the center of this 40-character long string. So then when we pass in that 40, it's really considering that width from here to here, including the white space. So now we're going to try to recreate that all on our own. First, we are going to need to import math because we're going to be able to use some new functions here. We're going to have to look at the floor of a division and that sort of thing and get like the number lower. But hey, let's give it a go. Now that we can import math, we've already done that. We can create a new function here called center. We're going to need to pass in that self-cured, obviously. In our case, we'll be using the string and the width. So let's get that code block started and we can do something new here. We can do string length. We can set that equal to the length of the string that we've been passed. So we have an integer variable here and now we can use a ground cover. You can name this variable whatever you want. I just think ground cover sounds kind of cool and it makes a little bit of sense, I guess. What you're going to do is you're going to do width and then minus or at least subtract the string length. So we're going to take that 40 that we might pass in and then we're going to take a look at all this and then we're going to divide that in half. So what we do here is we say sides equals the integer form of math.floor. Now math.floor, see, we're using our module here. We're using math and we're going to use our dot selector to get a function out of there and floor is going to round down to the nearest integer. It saves it as a float. It will return a float to you so you have to cast it or convert it with this integer function. That's what we're doing here wrapped around there. So inside the math.floor function though we do ground cover which is the difference between that width and the string length and then we can divide that by two. So now if we just quickly print out sides to see what we're working on and we can comment out this one up here and we can do print. We don't need to print anything. We can just run self.center and do self.string and then we'll pass in 40. Now if we run this we get 11. So in our case it's going to have this and you divide, you subtract 40 from that you subtract the width of the string so you have, sorry 40 subtract everything that's in here and then you divide that by two so you have these surrounding areas right here and since these are just space characters what we're going to be able to do is return sides or that number of white space characters sides times a string of spaces and then we can catenate on the string variable that we've been working with and then we're going to do the same thing again on the other side. So now when we print this out if we can catenate on some quotation marks again add that there and we run this we have this is a string and we have our quotation mark on one end and then the white space in between and all these. So if we print the normal function along with that we can see how well we did. This is a string, this is a string. It looks like we only have one space off so it looks like that means that they use the seal function sides equals integer math.seal or s-e-i-a there we go e-i-l and we use ground cover, just that same one here uncovered divided by two and this will round it up and this is a string, okay maybe that's not what they've done but you know, we don't know for sure I do recommend as always using the one that they brought in using the function that they have created because you just kind of should use that because they've obviously taken some preliminary measures or some things to make that the best and most easiest function ever or at least the way that it can be it's in its most pristine shape so don't use anything that we've created here when you're actually writing code but I just want to show you guys a way that it could be done or at least get you guys thinking about okay you can actually dissect some of the things that have already been offered for you this one here I don't have to worry about the top one see if we run this we get exactly what we wanted here a string centered in a width of 40 characters and obviously we can change this change the 40 to be whatever we wanted we can just say like 60 or something this is a string, you can see it's wider if we change it to 80 you can see it's even wider it's actually spanned across another line so you can do a lot of interesting things with this I suppose if you want to just center a string and make a nice little visual output and here's how it works or at least one way it could work on the back end so that's all guys, thank you for watching I hope you enjoyed the video and I will see you next time, bye