 One of my favorite uses for strings is actually something known as string formatting The entire idea is now instead of dealing with strings as just text. We can use them to build templates and Then I can inject I can use something known as the dot format method and I can inject Parameters into my template. I love working with this So, you know, let's say for example, I want to print for our you know sake math dot pi Well math dot pi has tons of you know numbers associated to it. It just trails on to Hypothetically infinity. I don't want to print a hypothetical infinity that No, so maybe instead I want to just print Three point one four. Well, how would I do that? And yeah, there are fancier ways where like I multiply it by a hundred and then I Converted to an integer and then I divide it by a hundred and I convert it to a string. I could do that It's not, you know, it's not illegal But it's a lot of work instead By creating a template. I'm basically saying well. Oh at some point in my string This is some thing that I want to replace with a Parameter and then so in this case you can see I've got these Curly braces going on here and specifically this first part Is representing which parameter so which Parameter Now it does start counting at zero and we will explore Why in just a little bit when we get to lists but that's effectively saying this math dot pi The zeroth element or the first element in the list, but then it can go on forward So you can actually see going on here something like Colon colon is now saying I'm going to give it some additional parameters Dot to f so I'm expecting a floating point number and I want it to only appear Two decimal places you can also see the exact same thing going on with this second one and let me change colors just to kind of Indicate a difference here. So in this situation Now I've got one colon 10d. Well, the one is again, which parameter? Well, and I know again. It's the second parameter, but we you know from a computer perspective It's at the one spot and oh, well, I know that this is going to be An integer. Why do we use a D? I don't know but that's what we use to represent that I'm going to be dealing with a Digit. I just talked my way into figuring it out But specifically this 10 Now what that is saying is you can't see the entire piece here So what I'm going to do is I'll draw it out up here What this format is doing is saying? Oh, well show me again 3.14 so only show me the first two decimal places of this floating point number Then show me the number four, but Men 10 spaces Since I don't know technically what Uh Since I don't know technically and based on my template what would be in here I'm saying that it needs to have a minimum of 10 spaces Well four as you might notice is only one character So in you know, we're seeing a one two three four five six seven eight nine Ten so what we would actually generate out is 3.14 a Bunch of spaces and then the number four. So let's actually sort of see this in action. There you are so First I'll start off with a super basic Version of string formatting again. I like to use the variable line That just is my go-to word for string formatting, but the first thing I'm going to do is just put in a Zero and a one that's it now you might remember we had an intersecting points homework assignment Where we may have wanted to do something like printing out Intersecting point colon and then had that variable inside of some parentheses or that those values inside of a parentheses Well this case now I'm saying well here's the template for that I don't know what the values of x and y may be at some point in time, but I know I want it to look like this Now if I came in and said my x was 3.7 and then my y was I don't know 4.2 Again, this is just making variables, but I could come in and say print line Dot format again the dot format is now saying I want to have some parameters associated to this for that zero Zero kind of fill in the blank portion and then that one fill in the blank portion And so whatever I want to be in the zero spot That would be the x because we're dealing with Cartesian planes and then whatever I want on the y so in this case why and so now I Look intersecting point six point seven comma four point two nice but what happens if instead of working off of something very simple again if I Had trailing decimal places I'm going to see all of them and you can see even it cut off my trailing decimal places at some point Well, that's where again we can use The colon to say for this fill in the blank spot. I want to add in a Some more Criteria or more formatting options is a better way to think of this and one of those in particular could be 2f Now 2f is effectively saying I want two decimal places, but if I just leave it as is. Oh, it'll work. Okay To f there we are Point two didn't do anything. It did just it rounded all the way up Point to f show me the last two decimal places and the same thing just for conformity sake one same approach so Only show me the last two decimal places now. There are other aspects of this. I could apply instead So let's change this up and say a new line Let's say I'll go 1 2 3 0 1 2 Now for this situation I'll I'll use different variables a 3 b 1 c 4 just kind of working off of pie here Now specifically if I just come in and print line dot format ABC They're all mushed together again. That's because I didn't create any spaces going on there But that's actually what I wanted to address we could come in and Let's add in something like 5d to every single one of these What I've just said now is each one of my You know fill in the blank, you know objects or fill in the blank spots needs to be a minimum of Five spaces large and if we were to highlight all of these spaces, so that's one two three four five And there we are same kind of thing one two three four five But we can go even fancier with these so as of right now everything is right aligned But if I wanted to go crazy, I might do something I believe that's where those need to go, but I could use the Less sand sign and that's gonna tell me go and make this left aligned and then I could also use the carrot the Exponential symbols what we would typically call it but make that centered and so oh Nice well Here's actually where this is where I would start to really Utilize this again. This is just fancy because you can I'm showing you because you can But one of the ways I would find myself really utilizing this Would be something like here Here and then one colon One colon how would I like to format this? Make it at least ten characters So Apologize I'm thinking in my head. So what I want to happen is a and or I'm gonna call them outer and Then inner Outer is going to be Just equal signed Times 15 so again what this is going to do just so we can see this Going on it's just gonna make a bunch of it's gonna make 15 equal signs and then for the inner I would say this is where like I would do something like test cases or test results actually would be a cleaner version of this test results And that is one two three four five six seven eight ten eleven twelve. Let me expand that to 30 Okay, so what have I done and what am I expecting? So again, I have a line Line has something at the zero spot and the one spot and the two spots So I have Effectively three Parameters or fill three fill in the blank spots that I want to work off of Now I also have two variables outer which is just going to give me 15 Equal signs and then inner which is just going to give me the string test results What I can do with this is now go line that format and In this case, I want something on the outer I want something on the inner and I want something on the outer so Make these 15 Equal signs appear here and in here and then inner test results I want to have in the middle and I want it to be centered and At least 30 characters long. So what I should see with this if I shift enter is Exactly that I get some nice little ASCII characters to represent, you know, I'm in a section And I have it on the outside and then I have test results What's really crazy if you really want to go down a rabbit hole just for a second because I'm doing this I Could make that zero again Or sorry, I can make that outer portion zero and So now these are referencing the same parameter So in this case It'll do the exact same thing, but now I don't have to have outer comma inner comma outer and again, so When one changes the other changes and so again now we're just again playing with string formatting But this is one of the most powerful tools I love using when I'm doing things like descriptive statistics data analysis or Even when I'm doing auto grading for students. I'll Segment each student so Adam Galeta and then Just to show off something as the what would be in here Results format score, and I'm just jumping down really results Tests past and then the score I'll just put you down here score 1.0 Let's say I only passed five out of the ten tests Out of ten tests Mm-hmm. That would show me in this case again tests past 0.5 But I could start going into this elaborate process of parsing out this so again Making sure to show that it's to F Or if I'm dealing with the fact that again, this is a decimal place. I might change this and Turn it into a Percentage So again, you're just making elaborations of what this template should look like in this case tests past and Then whatever the value of that tests score is Percent sign afterwards because I want it to be a percent and you calculate out your percent