Python 3.7: Ljust String Method

preview_player
Показать описание

Transcript:
Hello and welcome back to another Python tutorial my name Sam with mascot online as always don't forget to like share and subscribe to our channel in today's tutorial we're going to talk about the left justify string method or 2 L just string in Python what the ljust string method in Python does is it creates a new string with the previous strings content Justified to the left side of the shrink I'll just string method takes one required argument and that is how many index places should the new string Spin and that is how it justifies the shrink it also optional argument which is a fill character which way.

We can fill the string with a certain character now that Phil character defaults to one space if we do not provide a Phil character.

Argument so let's go ahead and take a look at all this in action is equal to MCO so we create a string now we're going to call the left justify stream at the end this we're only going to provide the required argument that's how many index positions we want to spend it. Just like that and we're going to say 10.

Notice we have.

Original string up three characters all right so we have that luck justified in the new string or three characters and in the Phil characters of white space which isn't the fault if we don't provide a Phil character argument is 7 index positions.

It's okay. I'll just and I will say 10, and then we're going to pass an! Character hit return and now we got our which consists of three characters that took up three total index positions now we will go ahead and fill the remaining seven and expositions.

Character.

Let's go ahead and take a look at an example when the string.

He's longer than original string is longer than the argument of index positions we pass with the L just string method so let's take a look at it be is equal to master code master code. 9 that animal safety. L just animals passing 10 and it returns noticed the original string is not left Justified it is basically Center in the string because we said we wanted 10:00 and expositions and Massacre. Online is longer than 10 so true that how long is actually is is 18 index position.

You guys have any questions head over to Mexico. Online otherwise we'll see you in the next tutorial.
Рекомендации по теме
Комментарии
Автор

I just found this channel and man o Man U are amazing

decorusshows
Автор

Thanks) Like the explanation, like the attitude)

akira_asahi