Welcome to this lecture in this lecture we're going to learn about a string which is very important
part of the Python programming.
So first of all what is this string so a string is a sequence of characters and you know the characters
are simply a symbol that is we have the 26 characters in the English language.
So these other characters which is ABC D all of these are the characters and the combination of that
characters is a string.
So when I say A B C D This is the string but normally we put this string inside these quotation so if
I say ABC inside this double chord This is your string which is your first string.
So a string is only the sequence of characters which will give you some meaning.
So if you say your name then that is also your string because it is also the combination of characters.
So we normally call the combination of sequence of characters as a string.
So let's see how to create the string and store them into the variables.
So if I say my string because we don't need to specify the types in these byte and programming it is
done dynamically by the Python interpreter.
So if I say hello and if I just create this this string and if I just want to print this which is or
my string it is going to give us the same string over here.
So a string can be created with the double code and it can be also created with the single code.
And if you see here let me create a new string with the same name.
But in this case I'll use triple but a single code over here.
And if I just close this with the same code if you do it in this way then this is going to work.
But if you just remove one code and you you see over here we have three opening chords and only the
two closing course it is not going to work.
So it is not going to work in this case you have to put three closing chord and then you have now created
three string which is Hello string.
You can also give the triple chords if you have to make a multi line statements or multi line string
so if I say my string and if I want to create the melody line string then I can see that flow and I
can say welcome to Let's make this multi line by going down and if I say welcome to the programming
world and if I just close with these triple chords then if I just it into you will see that we have
thus extended our string so it should be capitalists.
And now you can see we have the slice which means we add in the new line and this is our string.
The whole lot of string was created by these triple chords which is used to extend the multiple lines
in this case you can just go down and do multiple lines so this is also one type of commenting which
we just did in the previous Lexus how to combine that with the multiple line because the single line
commenting is with this has if you want a multi line comment it should be done with these triple chords.
So next is we'll see how to assist the characters in this string.
So let's make a string and let's see how we can this s is each of these characters from these strings
so let me say a is my string.
So instead of a this I make a new name and if I say python is the name and if I hit into and now if
you want to the C or phased items from this string you can do from the index so you can see here in
the python B is it position zero.
Why is it index 1.
D it too.
And similarly one increment at a time.
So if I want the character that is why then I have to give name first and give a square bracket and
inside that is square bracket you have to put the index so P is it index 0.
That means if you want to way you should put one over here and if I hit enter you are going to get away.
So you have to this s is through this indexing technique and just remember that in the string and in
the list the index is starts always from zero it is not from one.
Just remember that if you want to get this then you can do simply something from zero count from zero
one two three four five.
So if I just say name okay
if I say here name and five you are going to get the end but you can also do in the in other ways that
is a negative indexing which is minus 1.
So minus 1 is it mean.
So Yannis at index minus one in the pipe if I hit into you are going to get even if you want this negative
indexing from maybe R D if you want t with the negative indexing you have to count from minus one index
remained in the ease of these characters so yen is at minus one or is it minus two minus three minus
four so if the a sparse minus four you are going to get t.
So this the way to this get are face the characters from the string you can also slice the string so
he paces something like name and if you want to just phase the element from Y to D then you have to
count the index first because B is it zero index why is it one two three.
So if I say one two four because this position which is it there is and pauses and so if I read into
you are going to get white desserts but if I say name and one two three.
So if I say one two three you are not going to get a yes because although the order yet is it puts in
three but this is exclude and polls and that means it will count from one and go till three are basically
deal two.
So it will pain from one to two but not it will just include only two but not three to just exclude
this position.
So this puts in his exclusion position so you have to include the index that is bigger than that the
character you want to include.
So if you want to include from Y to T.
That means you have to include the index of Girard are all here if you want to index to be included
of all then include the index of the N over here.
So if you want to do something like from yes to yen then you have to do something like first of all
count so be there 0 1 2 3.
So inclusion position will be three and exclusion will be deal the last.
So last if it is still the last you don't need to give any index.
If I eat into irrigated so in so just remember that we can do a slice of this string and will learn
about this in the more detail in the list electors which is very important to learn about because in
the list also we can this get this idea for slicing and taking part of the list so a string can also
offer the same idea of slicing the string that is getting some part of the string so and next thing
what you can do here in the string is to delete this string.
So first of all before deleting let me just close this one and open the new terminal and here first
of all let's see how we can this I assign something to this string or not.
So if I say my string and now if I say that it is a string and if I want to assign something to these
string so if I do something like in the pages and fifth position I want to assign value.
So if you count the position and that is 50 0 to 1 2 3 4 5.
So that means it should include over here before G but it is not valid in the case of the string.
So is String object does not support item assignment.
So just remember that the strings are immutable that means the element of a string cannot be assigned.
So you cannot do this in the case of a string but you can do this in the case of the list or any other
that is Texas but in the case of string this is not valid.
So next thing is we can also delete this string so let's see how we can delete this string or not.
So if I said delete with this deal come on and my string would be my string and if I want to delete
only first character which is basically the D because the index is start from zero.
Then this is also not valid if I hit into a string object does not support item deletion.
So item deletion of another character deletion of these string is not valid but it will be valid in
the case of any other that I stopped the like list or a dictionary.
But in the case of the string this is not valid.
All you need to do is completely delete all this string.
So that should be done like this my string I didn't.
Now if you just take the my string it is not there it is not defined because it has been deleted completely.
So next thing in the list is the concatenation technique in the list.
Let's see how we can just concatenate they string.
So if a to string
Hello First a string that make a string too.
That is Python.
And if you want to concatenate this you have to do something like first of all take this string or seize
the SDR one and add this with SDR.
If you do this you are going to concatenate this string.
You can also do something like a multiplication of your string so if you want to get the multiple hello
you can do something like SDR 1.
Multiply it by three times.
So this automatic opposition is valid in the case of a string.
You can multiply your element.
You can also do addition which is basically a concatenation between the string and you can do this type
of operation is in a string.
So let's see some of the operations or some of the inbuilt the method of a string.
Now that includes one more time.
And here let's see some of the inbuilt fun some of these string.
So first of all I'll just make a simple string.
And in this string I'll say happy birthday.
So let's think that this is string or manipulate this string by inbuilt function of the python.
So first of all we'll see the capitalized funds and so let's see how this works.
So I'll say Happy Delys this makes your users into this dysfunction so when I just it into them you
can see that with these fountain only the first letter will be capitalized in other all the letter will
be in the lowercase.
So this is the capitalized funds in any face at stake again.
That is the my string.
It will be unchanged.
You can see this is the same string which is just created but we change with the capitals but it is
not happening anything over here.
Distances has not been deflected to the words in the listing because its strings are immutable.
They cannot be changed drastically.
This funds and if you want to make changes you have to assign it like this.
If I say my string and now I have to call inbuilt method in this the string with capitalize.
If we do this now you can see that Uri string will be tends to this capitalize.
Just remember that.
So next ones and we can see is the lower points and if I see a lower this is going to convert all of
these characters into the lowercase next one it would be obvious to the upper 1.
If we said upper.
This is going to things all out of 4 characters into the uppercase and this the way to see if we can
this convert to the uppercase and lowercase.
Let's see some other funds and so let's say that ABC is a string and let's call it is lower method over
here.
And if we do this then obviously this character in the lower case that means it to this written as a
true.
It can also do similar to this is this upper and it is also going to give us a true because that is
in the upper case.
So next thing is to strip.
So if you want to strip the spaces.
So if I do spend some spaces and ABC and some spaces and if you want to strip these blank spaces you
can simply call this a strip method and you will get that the name that is the characters.
Now this string without the blank spaces.
So this is a handy method which is the split strip method not split.
So this is important method.
You can also see the final method.
You can also take for the count method.
So if I say something like OK.
A B C D E F and if I just find some characters maybe C and if I hate Inter it is going to give us a
to the position.
It can also see the index method.
So these other some of the methods you can also see the len method which is going to take any object.
So if I do this then you are going to get the length of the string object over here which is passed
with the three characters.
So these are other some methods which are quite handy in the case of these string we have covered a
lot of things in this string part so in the upcoming lecture we'll learn about more complex data structures
and we'll just see some of the examples real world examples.
So see on the next one.