rjust This is a topic that many people are looking for. bluevelvetrestaurant.com is a channel providing useful information about learning, life, digital marketing and online courses …. it will help you have an overview and solid multi-faceted knowledge . Today, bluevelvetrestaurant.com would like to introduce to you Python Rjust String Method. Following along are instructions in the video below:
“And welcome to another python tutorial. My name is tom with learn python tutorial calm calm and in today s tutorial. We will talk about the hour just string method right justify sure method and the righteous justified string method. It pushes our string to the right shirring object justifying.
It to the right. I m sure if you ever used a word processing software or a blog. You ve seen the right justified content before so the string method gives us the ability to push our content to the right of the string object given that we give enough index positions. I should say enough index positions that are larger than our actual string the length.
So let s take a look at this are justified string method. So we ll crazy string and i ll say this is a shrink alright and now we re gonna do dot since this is a string method are just and then we re gonna give it a position..
How many do we want i m gonna say 40. All right so it s 40 index positions long that includes our string object here and then whatever. This is we add on to that so if i hit return you can see that it added whatever amount of spaces it needed to make this string out the new string object. 40 index positions long and pushes our string object to the right now.
The this argument. Here is required we can also provide another argument will do the same strength this is a string and we re gonna do our just now i. Do 40 am. The next one has to be in a string format our second argument this one s optional so we re gonna do plus and then close out our string and close out our string method with the parentheses.
And hit return and now you can see that instead of spaces up here. The spaces aren t default by the way..
So if we don t provide a character fill. Which it s referred to by python is if we don t provide a character fill. Which is this then it get defaults to spaces since we provided a character fill with the plus symbol. We now get pluses on the left side of our string object itself so that is basically our just but it you know it pushes it to the right.
But what happens if we create a string this is a string actually i want to do it this way. We re gonna do a is equal to this is and what i want to do here is see how long this actual string is so i ll call it length and a hit return all right. We got 16 index positions in this string. Object here all right so if i go a are just and i say 4 all right what s gonna happen here well it s not gonna you know say all right give me four to the right and then at our string object.
That s not how it works. What is gonna do is just spit back our string object just like that all right so..
Even if we had it our just for you know we put a character fill in there of maastricht it returns. So gonna do it it doesn t add any content in there so if our position positioning argument. Here is equal to or less than our string objects length. Then it s just gonna spit back the string object itself with no changes if it s larger.
But then it will push the string object itself to the right and fill in the content with either whatever we provide here or the default value of space. So one more look at this a dot are just and we ll do 50. And we ll fill them with exclamation points and hit return. But before i do that was explained this one more time.
We re getting a string object that we created up here all right via. They a variable and now we re calling our draw string method on that we re saying fill the new string object that we re gonna create with 50 index spaces and the are just is saying all right push our current string object of this alley to the right and we re gonna fill to the left and we re gonna fill our new index positions with the exclamation point so hit return you can see that s exactly what happens there we fill in the new string object to the left with exclamation points..
And our previous string object was copied into our new shrink object. And that s pushed all the way to the right now. If you have any questions about the are just string method in python. Please leave leave a comment on youtube or on our website at alarm python tutorial comm don t forget to like the video.
And don t forget to ” ..
Thank you for watching all the articles on the topic Python Rjust String Method. All shares of bluevelvetrestaurant.com are very good. We hope you are satisfied with the article. For any questions, please leave a comment below. Hopefully you guys support our website even more.