[no audio]
Friends here
we are going to discuss three important string operations.
They are like 'join', 'center' and 'zfill', right?
So how they are going to work?
Let me show you that by taking my
[no audio]
Python Shell. Of course
you can also write in your Python Script, but I am taking
simply Python command line.
Let's say I have a string called "python", right?
See my requirement is, from this 'x',
I mean from this "python" word
I want to create a "python" word by placing between each two
letters, two characters,
a space, I mean I want to create a 'y' data such that it has
to be in this way,
but I want to create that from your 'x' itself. Simply 'y=',
quotations, and inside that just "-",
'.join', then your 'x', so just join space inside of your 'x' between
your characters.
Simply print 'y'.
[no audio]
Right. Otherwise directly you can print. See as of now
I am printing 'x' in this way. Now 'print', you can also do something like,
[no audio]
suppose I am adding "*" between two characters in
my given 'x'. See the output. Or I want to print one by one letter,
then add "\n". You know "\n" means new line. See that, you're
getting your string in multiple lines. In each line one character
because "\n" purpose is. Otherwise, let me add "\t". See the
output. You're adding tab between two characters of your given string.
[no audio]
Right. So this is the importance of your 'join' string.
Right. Fine. Then the next one is 'center'.
See guys, sometimes you have some multiple strings and you
want to print all strings in the center of your terminal
or in the centre of some width of your terminal.
Let's say I have a 'my_str' called simply "python",
[no audio]
and I have one more new string called
[no audio]
"python scripting", and let me take some third string
'my_str3='
[no audio]
"string operations".
[no audio]
Okay. Now see that I am going to print,
first of all let me take only 'my_str'
'.center'. So all strings I want to print with the width
of suppose some 20 characters. Now, first of all let me print
my first string.
So in 20 spaces your string is there in the middle of that.
Likewise I want to print,
let me use format. All strings at a time
I want, I am going to print.
[no audio]
Right. So in the next line, I want to print your
'my_new_str.center(20)'.
See the output so that you can understand
what is the purpose of this 'center'
[no audio]
Then I want to print your
[no audio]
next variable called "my_str_3
.center(20)', and see the output.
Something missing. Let me see that. Yeah, quotations is missing,
right. See the output.
[no audio]
'center', yeah somewhere spelling mistake.
[no audio]
See.
[no audio]
Nothing is there guys, whatever the length you're giving, first
your Python will take that much length, in that length
it will try to print your string from middle towards left and right.
That's it.
Okay. Now 'zfill', zero add, zero fill.
[no audio]
Let me do one more thing like
'print', let me take simply your string,
I am printing. You're getting something
no, but I want to print this string,
[no audio]
okay, with some 10 spaces.
[no audio]
And anyway your "python" string consists of only six characters,
the remaining four places
I want to pad with 0 towards left. See that.
Total spaces are ten, right. So you are given string length
is six. Remaining four spaces towards left
I want to pad with zeros,
so 'padding', this operation is called actually 'padding'.
Right. This operation is called actually the 'padding'.
[no audio]
Okay, so guys
these are the operation uses of your 'join', 'center' and 'zfill'
Right. Okay guys,
thank you for watching this video.
[no audio]