Some String Functions Part 2

Lesson Details:
September 17, 2020

Video Transcription: In continuation with the previous lecture we are going to discuss strings again click on the project right click on the project my strings then-new Python file I'm going to give it the name string - ok so this is our second program in the project my strings this video is brought to you by Appy Pie’s Academy, so I'm going to take a string variable called College st. Stephan's 3/8 difference okay so I'm going to use a method string function method is the term used for functions so I'm going to use this method called a strip so what I am going to do is first let me give the command strip function removes the leading and trailing leading and trailing spaces right so blank spaces will be removed either they are leading or trailing in the beginning or in the end so I am going to right brained College dot strip okay so in the beginning there is space in the beginning of the value st. Stephan's that will be removed in the end also there is space that too will be removed so let's click on the python file name string - and you can go to run this is another way to execute a program you can see st. Stephan's is printed and the spaces they have been removed okay quite simple function now what we are going to do is we are going to use a function called replace and replace function replaces the occurrence of a crater occurrence of a character with some other character okay so what I am going to do is I am going to take another string variable let the name be city and the value I'm going to give is New York okay so what I want to do is I want to replace the occurrence of the letter Y with Zed so what I would write is city which is the name of the string variable city dot replace you can see the syntax carefully then the first argument will be the character to be replaced and second argument will be the character that will be replacing this okay so click on the name of the program click on right click on the name of the program click on run and okay there seems to be some problem yeah I have not used print statement so I would write print again right click on the name of the program click on run yeah you can see instead of New York it is printing New York why because Y has been replaced the width Z right so another function we are going to use a split function which splits a string in two parts so spread function splits a string based on a separator those days you there ought to be a separator like comma or some space or any kind of separator that will decide where to split the word or your string so I am going to write like group Chaitra is a holy city okay in Haryana okay India so this is the string it's a string constant right so afterwards what I will do is I will use dot split after writing this string I will use dot split okay let me go to the place dot split okay I will use split then within spread I am passing this within double quotes this correct a coma so this whole one is the strain okay and split is the function comma is its argument so that means this string will be split in two sub strings and the separator is comma okay so let's execute the program run it yes the output has been there Kurukshetra is is a separate string a holy city in Haryana India is a separate string. 

Course content