0:00 hello everyone I am pradnya in this video we are going to study chapter number nine that is string manipulation in this chapter we will study different operators which we can apply on the stream and some of the functions and methods which are used to manipulate string so let's get started we are quite familiar with the string as we have discussed in the earlier chapter so let's recap what is string string is a sequence of characters even in Python we can write a single character as a string and string can be enclosed in a single code in a double code as well as we can use triple quotes also the strings are immutable immutable
0:45 means we cannot change the content of the string at the same memory address if you are creating any new string it will get created at the new memory address we can access the individual characters of the string by using index we can access string in both the direction forward Direction and The backward Direction so index starts from 0 when we access the string in the forward Direction and the index starts from -1 when we access the string in the backward Direction now let's try to understand One More Concept that is traversing a string
1:33 traversing means accessing all the elements of the string one by one and you know we can access the elements of the string using index we can use looping statement to access the individual elements of the string so we can use membership operator in along with 4 or you can use range function also along with 4 to access the individual elements of the string so here is a piece of code for that here we are initializing one string to a variable name and using for Loop we are accessing the elements of the string and we are printing it so the output of the string will be it will print the
2:20 individual characters of the string similarly to Traverse the elements of the string one by one we can use the range function also here the starting value is 0 as the index of the string always starts from zero and the upper limit is the length of the string so length of the string means total number of characters so the total number of characters are 6 and the range function doesn't include the upper limit so this Loop will execute from 0 to 5 which are the index of this string so p is at the index 0 and this is at the index file so we will get all the elements of the
3:07 string again we will get the same output so in this way we can Traverse the elements of the string and then whichever operation we want to perform on the string we can go ahead with that let's discuss some of the operators which we can apply on string the first is string concatenation operator so plus operator we can use as a string concatenation operator the second one is star it is called as string replication operator and the third one is membership operator in and not in and the fourth category of operators is comparison
3:53 operators even you can call it as a relational orbitals so all these six comparison operators we can apply on the string we are already familiar with all these operators as we have discussed in earlier chapters now let's try to understand how it works on string so the first operator is concatenation operator for that we are using plus when we use this operator with numbers it adds the two numbers but when we use this operator with string it combines two different string into a single string so let's take example the first ring is Python and the second string we have
4:40 programming and we are applying this concatenation operator so these two different strings will get combined into a single stream so you can see here we got one single string by combining the two different string it will work if both the operands are string but the concatenation operator will not work if the operand is of different type other than string so here we can see this is a integer value and this is a string value so this is not valid operation so plus operator in case of string works as a concatenation operator which combines two different steam into a single there is one more operator we are going to
5:27 apply to string that is string replication operator for that we are using star you know when we use this star operator with numbers it works as a multiplication operator but when we use this star with the string it works as a replication operator it repeats the string for the specified number of times so this is the syntax you can mention this number after the string or before the string let's consider one simple example this is one string I have considered I want to repeat this word python three times so I am multiplying it with 3 so you can see here this got repeated three times this is first time this is the second time and this is the
6:14 third time you can use any character as a string or even numbers as a string so here are some of the examples in the third example you can notice we have written first number and then the string so in both way you can write it so to replicate the string or to repeat the string we can use star operator the third category of operators which we can used on string is membership operators we have already discussed membership operators in the previous chapter the first membership operator is in and the second membership operator is not in it Returns the result in the form of true or false in operator returns true if any
7:02 character or a substring exists in the mainstream otherwise it will return false so it will check the existence of the character in the Stream and the reverse of in is not in if the character doesn't exist in the string then it will return true otherwise it will return false so this is the general format to write it we will check this string in the main string so let's try to understand the working of in with some simple example I want to check the word Pi in the mainstream python so you can see the word is present is exist in the mainstream so we
7:48 have got the result as true in operator checks the exact case of the string if it doesn't match we'll get the result as false so here you can see the p is lower case and here p is capital so it didn't match and we got the result as false now let's check out for the not in operator if this substring or character not present in the mainstream we will get answer true so you can see here this four five C doesn't exist in the mainstream so we got true the fourth category of The Operators which we can apply on stream is
8:34 comparisons operator so here are these six comparison operators which we can apply on string it will compare the string character by character so let's try to understand how the characters are getting compared the first one is equal to so a is equals to A yes both the characters are same so we will get the result as true as comparison operator also gives the result in the form of true or false the second one is not equal to a is not equal to B yes both the characters are different that's why it is also giving result in the form of true so these two
9:21 operators were obvious we could understand how we are getting the result but what about these four comparison operators check out this example small a is greater than capital A and we are getting answer as true how we are getting the result in the form of true because the characters are compared internally based on the Unicode values we have discussed some of the encoding system in the first chapter every character has some value associated with it so when we try to compare the characters actually the value got compared for maximum numbers the ASCII
10:08 value and the Unicode value is same so unique code value is also known as ordinal value so here there is one table in which I have listed sum of the ordinal values for the characters which we use maximum so capital A to Z has the value 65 to 90. small A to Z has the value from 97 to 122 and the digits from 0 to 9 as the values 48 to 57 so when we are trying to compare these two strings the ordinal values will get compared so the ordinal value of a is 97 and for Capital a is
10:55 d65 so it is clear that 97 is greater than 65 that's why we are getting result as true in the same way other operators also works on the string it will consider its ordinal value if you want to find out the ordinal value of that character you can use ORD function and if you have ordinal value and check out the character for that ordinal value we can use the care function so ORD of a will be 65 and if you have ordinal value you can take the character for that if I will write character of 65 we will get
11:41 character a in this way we studied concatenation operator replication operator membership operators and the comparison operators [Music] consider that I have a chapati and I want only a part of it or a quarter of Aid so it is also called as a size of that chapati similarly we can take out one part of the string it can be called as a string slice so let's understand how we can take out the part of the string so here is the syntax first we have to mention the name of the
12:29 string then in square bracket there are three parameters so the first parameter is the starting index here we are doing slicing with the use of index and you know the starting index will always be 0 so the default value of the starting index is 0. next we have to mention the ending index which indicates the index till where we should continue the slicing of the string the last parameter is Step which indicates the number of character to be skipped while slicing there are different variations to write this form so let's consider one by one
13:14 in the first variation we are mentioning the start value and the stop value but we skip the step part because it is optional we can skip it so it will slice the character from start to stop -1 the ending index doesn't include in the slicing so the starting value is 1 means we are starting from this index and I have mentioned 4 but it will not go till 4 it will take one less than that so from first index two third index we are getting this slice of the string so output is y t h let's consider the second variation here
14:02 we have mentioned the start but we skip the end if we skip the end it will continue till end of the string so let's check out this example the beginning is one means we are starting from here and we didn't mention the end so it will go till end so we will get the string from y to n let's check the output we are getting correctly let's take the third variation here I have omitted the starting part if we skip the starting part the default value of start is 0 so it will start from 0 and it will go till stop minus 1. let's take this example we didn't mention here start so it will start with 0 so it will take this index and for end
14:51 we have mentioned 4 so 4 will not get included so till 3 it will take it so the beginning is 0 and the end is 3 so we will get this part of the string that is p y t h in the fourth variation I skipped all the parameters so it will consider the whole string so it will print from the beginning till end let's try to understand the last variation here we have mentioned all three parameters so the slicing will start from the start index and it will continue till stop minus 1 and by step it will skip the characters while slicing so let's consider one example
15:37 the starting is one so we will start with the index 1 the ending is 6 means 6 minus 1 will be 5 because the upper limit we don't include in the slicing and the step is 2 means we will skip the two characters so beginning with 1 means we will get first y now skip two characters so first character and second character we will skip then we will get this third character Edge so we are getting H here first we got y now again skip this two characters so H will get skipped o will get skipped and the next character is n so we will get the n in the same way you can write negative
16:22 index also to Traverse the string in the backward Direction the next important topic of this chapter is string functions and methods we have to study some functions and methods which we can apply on the string to manipulate it there are total 21 and these are very simple so don't worry don't get scared from the name itself we can Define the usage of that function so here is the list of the functions and methods which we will study one by one with some simple example and we'll try to write programs based on some of the functions so let's get started
17:12 the first function is len function it is used to count the number of characters in a string we have to write the function Len and inside the bracket we have to mention the string it can be a string literal or the name of the variable so let's consider one simple example Len of this string so we have written the string here and you can see there are total four characters in it so we got the answer as 4. even we can store the string into a variable and then we can mention that variable name in the bracket and the number of character in the string is 3 so we got answer 3 it's simple it counts the number of
17:58 characters in the string second method is capitalize don't worry about the difference between function and Method here we have to keep in mind the name of that function or the method and the usage of that so the capitalize method converts the first alphabet of the string to the upper case it only converts the first alphabet other alphabets will be in the lower case so this is the syntax to write capitalize method first we automation string then Dot and then this is the method so let's try to understand with one example here is the string and then
18:46 capitalize method I applied on this string so you can see here only the first alphabet got converted to the capital let's consider one more example the string is Python Programming and I applied the capitalize method on it you can see here only the first alphabet of the string got converted to the upper case and even though the first alphabet of this word was Capital it got converted to the lower case so the first character only will get changed to the uppercase other characters will be in the lower case so this is the usage of capitalize method
19:34 the third method is count it will count the number of occurrence of a substring in the mainstream so how many times that a part of the string is present in the main string that we will count so here is the general form first we have to mention the string then count method and there are three parameters the first parameter is the substring which we have to check in the mainstream and this start and end indicates the starting part and the ending part of the string from where we have to start counting so let's take one example in this string I have to count the occurrence of the
20:21 character a so you can see here the a is two times in this string so the occurrence of this is 2. let's use this start and end parameter and take one more example so this is the string programming I have to count the occurrence of the string mm in the main string so it should start from 1 and should end at 5 but you know the upper limit doesn't include in the string so from 1 to 4 it will get change so the index this is the index 0 then this is the index one two three and four so from 1 to 4 we have to
21:06 check and the mm is not present so we are getting answer 0. so the count method counts the number of occurrence of a part of the string in the mainstream next method is find method it will find the index of the substring in the mainstream if it founds it will give the lowest index if it doesn't form it will return minus 1. so this is the syntax string dot find the first parameter is the substring for which we have to find the index and this is the starting and the ending index of the string so look at this simple example this is the string I love India
21:54 and I have to find the index of this word this is the substring and I have to find the index of this in the main string so you can see here this I will start at 0 second we have space so it will be 1 and the L is at the index 2 so we will get the lowest index so we are getting 2 here let's consider one more example here I have initialized string to the variable and I have initialized this substring also to one variable now I have to find out the index of that so here is the variable sub and the starting is 1 and the ending is 5 so it will start from the index 1 and will go to the index 4.
22:42 this is the index 0 1 2 3 4 and you can see your word doesn't exist in this range what we have specified here so we are getting the answer minus 1 if the find function cannot find that substring in the specified range it will give the result as minus 1. there is one more method which is used to find the index of the substring that is index method it will also give the lowest index of the substring from the main string then what's the difference between these two methods find and index find will give the result minus 1 if it cannot
23:28 find but index will give the exception value error if it cannot find so the syntax is similar as find here we are writing index instead of fine I have considered the same example here the string is same and we are finding the substring in the main string which is present at the index 2. so this is the lowest index and here also I have taken the same example the string I have initialized to one variable Str substring we have initialized to one variable sum when I am trying to find out but it couldn't find in the train so we are getting the value error substring not found
24:15 so this is the difference between these two methods find function will display minus 1 and the index will raise the exception if it couldn't find the substring in the mainstream sometimes we need to validate the string like when we are filling the inquiry form or when we are filling the admission form that time we use this type of method the first method what we have to study that is is a num the method starting with word is will always give the result in the form of true or false if the string is consist of alphanumeric characters then it will return true otherwise it will return
25:01 false if there is a space in between the words of the string then also we will get the false so this is the syntax first we have to write the variable string or you can directly write the string constant and Dot is I'll num so let's check out the simple example you can see here there is one string in which we have alphabets also and numbers also so we are getting the result as true let's consider one more example in this string there is a space in between the two words and when we are trying to apply these is all now method on this string we are getting Reserve false
25:46 so space is not a alphanumeric character the stream should have only alphabets or numbers then only you will get the answer as true in the same genre we have one more method that is is Alpha it will return true if the stream contains the alphabets or false otherwise so if you want to enter the name in the admission form you cannot write other special characters into it that time we can use this type of method to check whether the string is consists of only alphabets or not so this is the syntax string dot is Alpha so here is one
26:32 string and we are applying the easel for method and it contains only alphabet so we are getting the answer as true in contrast to that here is one string which consists of some alphabets and some numbers so we are getting the result as false suppose we are generating the marksheet and we have to enter the marks so in that column we cannot enter any alphabet that time we can use this method is digit it will return true if the string contains digits otherwise we will get the answer as false so syntax is similar string dot is digit
27:18 let's consider one simple example here is a string and in that string we have the digits so when we are applying each digit method on that string yes we are getting the digits so the result is true in this string I have mixed some alphabets and some numbers and when we are trying to apply this method on the string we are getting the result false as there are some alphabets also the next method is ease lower method which will give the True Result if all the characters are in lower case or false otherwise if you want to enter some data which should be in only lower
28:04 case and if you want to check it whether it is in lower case or not then we can use this function is lower so this is the syntax let's consider one simple example here one string I have written computer and we want to check whether it is a lowercase or not yes all the characters are in lower case so the result is true now come to the next example here the one letter in the string is capital so when I applied this is lower function on that string we are getting the result false it's very simple it will check if all the characters in The String are in lower case or not let's continue with some more methods so
28:52 we have now ease space it will return true if all the characters in The String are spaces means it will check out for the space otherwise we will get the result as false the syntax is similar string dot is space let's consider an example here I have taken one string it contains one space so when I am applying it on that string I am getting the result as true there should be at least one space in the string then you will get the answer true otherwise false so look at this example there is no space in that string so when I applied it on that
29:38 string I am getting the result as false you might have noticed that whenever we enter our first name last name it should be in capital so we can use this function to check whether you are writing the details or typing the details in capital or not with the function is upper it will return true if all the characters in The String are in uppercase otherwise we will get the answer as false so this is the syntax string dot is upper now let's check the example here this is a string in which all the characters are in upper case so I am getting the answer as true and in
30:23 this example one letter is capital other are small case so I am getting the answer as false let's continue our discussion of the methods with some more methods the next method is the lower method it will converts the string to lower case it's very simple much explanation is not required from the name itself you can tell what is the usage of this method so in this example I used one uppercase string and applying the lower method on it so I got the lower case string even we can apply this lower function where we have the mixed characters it will be
31:10 applicable only on the alphabet and it will get converted to the lower case if we have function to convert the string to lower case then surely we will have the function to convert to uppercase so the upper method converts the string to the upper case the syntax is similar to lower so let's apply the upper function on the string in which all the letters are in lower case so the output will be a string where the letters will be in the upper case like lower we can apply the upper also on the mixed data in which only the alphabet part will get changed to the upper case
31:57 the remaining data will be as it is [Music] we have some spaces in the string then these three methods we can use to remove the spaces from the string the first one is L strip the second one is R strip and there is one more option stream so let's try to understand how these methods work the first is L stream it removes the white spaces from the left most end if we have some spaces on the left side then it will remove it and if you want to remove the spaces from the right most in then we can use
32:44 our strip method for that so it removes the white spaces from the rightmost end and if you want to remove the spaces from both the end left most and the rightmost also then we can use the strip method so here is the syntax string dot L strip and the other syntax is also similar to that so let's consider one example for each of these methods look at the first string here I have given some spaces in the beginning and some spaces at the right side so L strip removes only the spaces which are in the left most end so it got removed
33:31 but the spaces at the right most in are still present in the string so L strip only removes the spaces from the leftmost in in the same way R strip removes the spaces only from the right most end so the spaces in the beginning are still exist or are still present in the string now let's take the working of strip method here I have given some spaces on both the sides and strip functions removes the spaces from both the side so we got the string with the removed spaces let's discuss some more methods we have
34:18 starts with and ends with so what is the use of these methods the result of both the methods are in the form of true or false so starts with method returns true if it starts with the specified substring otherwise it will return false and the ends with method will return the true if the string ends with the sub here it should come ends otherwise it will return false so here is the syntax we have to check out whether the string is starting with this substring or not and here we have
35:04 to check out whether the string is ending with the substring or not look at this ring I have taken one string face boom and I want to check whether this string is getting started with this word face or not and yes it is starting with the word face so I got the result true if I want to check whether that string is getting started with book no it is not getting started with boom so I got the result as false the ends with method also works in the similar way check out the stream I have taken the string Instagram and I want to check whether it is ending with this substring and yes it is ending with M so I got true and here
35:51 I am checking with some other word so I got false studied how to change the case of the string from lower to Upper and upper to lower there is one more method we have that is title which will convert the string into a title case what is the title case title case means first alphabet of each word will be in the upper case so here is the syntax string dot title let's consider one example here is a string B yourself which is in lower case and when I am applying this title method
36:38 on this string you can see here the first alphabet of each word got converted to uppercase and in the second example I tried one string with all the letters in upper case so this string also got converted in which only the first alphabet is in uppercase we use title method to change the string into a title case but if I want to check whether the string is in title case or not then we can use the method is title
37:23 so it will return true if the string is in title case otherwise we will get the result as false so this is the Syntax for that string dot is title so let's check out whether this string is in title case or not you can see here the first alphabet of each word is in upper case means it is in title case so we got the result as true and look at this string now this is not in title case all the alphabets are in uppercase so we got the result as false there is one more important method which we can use for string manipulation is
38:10 replace so replace method replaces a substring from the main string you might have used this replace Concept in Ms word also which will replace that word with another word in your document so this is the general format of the replace method this is the old string and what we have to replace that we have to mention here after comma so let's check out one simple example here is the string C plus plus programming I have to replace this C plus plus with the word python so I have written for C plus plus and then python so instead of C plus plus we will get the word python
38:57 now you can understand the logic behind the replace option which is provided by the MS word foreign let's add one more method to our list of methods that is join method so what it does join method joins a string or character after each member of the sequence it can be a string least Tuple said dictionary also so after each word of the sequence the specified string or character got joined so look at the syntax the specified string will get
39:43 joined to each of the word of the sequence of data so let's try to understand with one simple example I have to join these character star in this string so after each character you can see here the star got joined let's take one more example where I am taking one list now I have to join this sequence of characters consist of two hash symbol so after each word of the list it will get joined so first what is data and the second word is science in between you can see the hash symbol got joined
40:28 when we are taking these sequence it should be of string type here you can see I have included one data which is of integer type and then I am trying to join it so we will get one exception that is type error so using join method we can join one character or a string to each member of the sequence we are almost at the end of the list of the methods which are used to manipulate strings so the next method is split method from the name itself we can Define split method is used to split a string into a list of strings and it
41:16 will separate by a separator so here is the syntax stream dot split and in bracket we have to mention a string or we can mention the character and the string will get split based on that separator so the default separator is space if you will not mention any separator the string will be separated based on space so look at this example here there is a one string cloud computing and we are applying split method on this string and I did not mention any separator here so the string got separated based on string so we got one string cloud and the
42:03 second string Computing because in between them we have space what if we will give the separator here the separator is O and now look at this string the string will get separated based on o so we have IL before also we got one string here and then after o till the next occurrence of the O we have got this second string and the remaining is n and this is the third string the separator will not be included in the string finally we are at the end of the list
42:50 the last method is partition partition method is also used to split the string it will split the string at the first occurrence of the separator and it will return a tuple so that Tuple consists of three parts the first part is the part before the separator and the second string will be the separator itself and the third part will be the string after the separator so here is the syntax string dot partition and in bracket we have to give the string or any separator let's try to understand the working of partition method using one simple
43:37 example we have considered one string here and the big is the separator So based on this word the string will get separated so before the separator the first part is dream so we got one string here now the second part will be the separator itself so second string is the separator and the third part will be the string after the separator so after the separator we have this is the third string and partition method returns a tuple so you can notice here we are using brackets both split and partition method separates the string but there is a
44:24 difference between them let's try to understand split method separates the string at any occurrence of the separator but in case of partition it splits at the first occurrence of the separator and the second difference is split method returns a list type and partition method returns a tuple and the third difference is in case of split method by default the stream will get separated based on space so the length of the list will be the number of words but in Partition always the length will
45:11 be 3. as you can see in this example always the length will be 3 because it will take the separator itself and the part before the separator and there is one more part after separator so the length will be always 3. so far we discussed some of the important concepts related to string theoretically now it's time to implement it before writing any program I would suggest you to practice all the methods and the functions we studied so far so the effect of that function will be clear to you and later it will be easy
45:57 to write complex programs so let me demonstrate some of the methods and functions let's apply the first function Lane function on the string it will calculate the number of characters in a string so here we are taking one string in the variable Str now let's print the length of the string Len is a function so we are writing length function and inside the bracket name of the variable check out the output enter any random string so the length of the string is 4 because the number of characters in this string
46:43 are four now let's use capitalize method which will convert the first letter of the string to uppercase so apart from Lane all others are methods so syntax to write the method is first we should write the variable name then Dot and you can see here the list of the methods are displaying here you can use whichever you required so now we want to use capitalize method let's take the output I will enter one string where the first letter is in lower case and other letters I will try to enter in capital so that will come to know the effect of
47:30 it you can see here the first letter of the string got converted to the upper case and all other characters are in lower case there is one more method count which will count the occurrence of the substring in the mainstream so let's use that so the syntax is first we should write this variable then we have to use the count method you can see here we could see the syntax also press Tab and I have to count the appearance of a in the string so accordingly I will enter the string so
48:16 let's check the output I am going to enter one string data because I want to check the occurrence of the letter A so you can see here a is two times in the string so we are getting the output 2. okay let me demonstrate some more methods we studied two methods one is index and one is fine which will display the index of the substring from the main string so the syntax is Str dot find press tab you can see here the syntax also I want to search one word in the string so I will use this word accordingly I will enter the string in the same way we
49:03 can use the index method also so let's check the output I am going to end the string where I will find this word so that you can check the index press enter so you can see here we are getting the index 2 because the word starting with the index 2 and it will give the lowest index so I is at 0 then at 1 we have space and at the index 2 we have the letter L so we got the lowest index you know the difference between find and index find will give the result as minus 1 if we couldn't find that and index will raise an exception
49:51 now let's move ahead with some more methods we will use now lower upper which will convert the case of the string so I am going to use the method upper which will change the string to uppercase and we will comment out this statements okay let's run the program and check the output now I am going to enter one lower case string so we will get the upper case similarly you can practice all other methods now let's try to implement some of the methods to write program for string
50:39 manipulation [Music] we are going to write a program to count the uppercase characters lowercase characters and the number of digits and symbols present in the string so how we can do it so let's take one string first of all we have to iterate through the strain using some looping statement then we will compare each character of the string using the methods if we get it then we will keep on adding to a variable I am taking some variables and initializing to 0 so that in that variable I can keep on adding so you I
51:26 am using for uppercase L is for lowercase as I am using for symbols and D I am using to count the digits now let's use for loop I am taking one variable CH to iterate through the string for CH in Str right colon so the block of 4 will get created now first of all we have to check whether the letter is a upper case or not so for that we have function is upper so I am going to select it then write the colon if this condition is true means the letter is upper case then we will keep on adding for that I have taken the variable U so I will add 1 to
52:13 the variable U so in this way it will keep on incrementing and finally we will get the count of it in the same way we have to check for lower and four digit so now I will use l if check out for lower down and to count the lower case letters I am using this variable L be careful with the indentation now check out for digits so each digit method we can use for that if it is a digit to count that I have taken the variable d now at last we have to check for symbols so how we can check for symbol as there
52:58 is no proper method for that if we are entering any string what that string can contain it can contain alphabets it can contain numbers there can be a space between two words and some special symbols we can type so to find out the symbol first we have to remove the alphabet and numbers and the space so alphabet and numbers we can check with is lnum method and we can check the space also so we have to take out this from the string then the remaining will be the symbols so let's write the condition using L if
53:46 CH dot is L noun function will check that it should not be a alphabet or number so I am writing not equals to True means we are not considering alphabet and numbers and along with that it should not be space also so I am taking CH is not equals to space it means if we remove the numbers and alphabets and space the remaining can be the symbols in hours so for counting the symbols I am using the variable s so we will increment it the else part is optional we can skip it the counting part is over now let's print it
54:32 so we are printing the uppercase letters lowercase letter digits and symbol let's check the output enter the string which consists of some uppercase lowercase characters and some digits and some special symbols also so I can write a random string you can write according to you now let's enter and check out you can see here there is a one uppercase character and remaining are lowercase characters we have digits R3 and the symbol we have exclamation that is one so we are getting the perfect answer you can try out for different inputs [Music] [Applause] let's write one more program for string
55:19 manipulation in this program we have to count the number of words and the number of characters you know number of characters we can count using the alien function now how to count the words to count the number of words I am going to use the split function check out the working of the split function I am using one variable to split the words so we have the split function Str Dot split by default it will split using space as a separator we have split the string into the words and we have got the list but I want to check the number of the words so I am using here l e n function so that I will come to know
56:06 the total number of words in that list and that only we required now let's print the number of words which we have stored in the variable w now one thing is remaining that we have to count the number of characters so we will apply the alien function on the string so we will get the number of characters of the string so let's apply the length function on the main string let's check the output you can see here there are two words so we got the number of words equals to 2 and the total number of characters are 11 it will count space Also [Music]
56:52 [Applause] we practice some of the methods now let me demonstrate the slicing of the string so we are going to write one program for palindrome string so what is palindrome string when we read the string in forward direction is exactly same if we read the string in the reverse directions can you tell me some of the examples of palindrome string it can be a dad or it can be a cutter or it can be a mom or you can use this word refer so try to read these strings when you will read this string in forward Direction it will be exactly same if you read this string
57:38 in the reverse Direction so we have to write the program for palindrom string we have to check whether the entered string is palindrome or not so let's take the input first we have taken one string now we have to reverse the string then we will compare both the strings if they are equal then the string is palindrom otherwise it is not a palindrome string so to reverse the string I am using the concept of string slicing you know we can read the string in the backward direction using the negative indexing so let's save this reverse string in one variable Str in bracket I am going to skip the start I am going to skip the end also so
58:24 that whole string will get accessed and I'm using the negative indexing minus 1 so the string will get freed from the backward Direction so we got the reverse string if both the strings are equal we can print the message the string is palindrome and if it is not equals we can write that in the else part that string is not a palindrome string so let's check the output first I am going to enter a word which is a palindrome so we got the correct message now let's try to enter the
59:11 string which is not a palindrome you can see here we are getting the message not the palindrome with the string slicing and the methods you can write many programs so try to write as many as possible so in this video we studied string data type in detail hope you have understood all the concept if not you can write in the comments in the next video I will cover chapter 10 that is list manipulation so till then keep studying see you in the next video
1:00:00 thank you