Some String Functions Part 1

Some String Functions Part 1

Lesson Details:
September 17, 2020

Video Transcription: In this lecture we are going to learn about strings so I'm going to create a new project go to file new project this video is brought to you by Appy Pie’s Academy, and here we are supposed to give the name to the project I am giving the name my strings click on create and if you want to create new window you can click on new window I have clicked on this window only now it will take some time because it's creating virtual environment different libraries are being loaded so because this is the new project it's going to take some time so as you know a string is nothing else but it's a group of characters and Python has got a very rich library of string functions where by we can manipulate with the strings I will be covering this topic in at least two lectures in this lecture I will be like talking about some very basic string functions okay so now right click on the project my strings and as usual go to new and choose this Python file ok click on this so we are going to give name to our Python program so I'm going to give it the name string 1 ok click on OK py extraction will be automatically so fixed now I am going to take a string variable name is equal to Anand Mahajan it has been assigned the value are Anand mahajan the name of the string is freeing variable is name so this is your now I'm going to give the command using the hash symbol the characters of a string are indexed in such a way that the first character is at index 0 right and second at index 1 and so on and so because there were multiple line comments each line has been NASA fixed with hash symbol it has been preceded with hash symbol so all these three lines they were taken as comments so when I would write print name square back at zero it will give me the very first character which is a go to run okay run this program choose string one click on this yes a why because we have printed name zero so zero index number is of the character a now I would write name within square bracket four so it will give me the fifth character why fifth because index starts from zero so I will click on this run run the program it's giving D because D is at index number four which is in fact the position number five okay now you can use a range also when I would write suppose 1 : 4 what does it beat it means the substring starting from the index 1 till the index 4 minus 1 in this case that will be 3 that will be printed click on run so it should be an e and E and E and sorry N and right because we started from index 1 that is N and we went till n n a and this substring was printed why because when I mentioned the range as 1 : 4 that means 1 from 1 2 3 index number 3 ok so next I am going to talk about a very simple function which is called Len Len function returns that is gives the length of a string now what is the length of a string length of a string means the total number of characters in a string so print I'm going to write len and as an argument I will supply the name of the variable which is named click on run yeah choose this okay so let me run string 1 and the answer is 13 why 13 because the total number of characters in the string name are 13 always remember space is also treated as a corrector so it will also be counted space will also be counted remember it now I am going to talk about another simple function which is called lower so lower function what does it do is it converts the string in to lower case into lower case okay so how to use it I will use first print in order to print the output then let me write name which is the name of our strain dot lower name dot lower see the syntax using which we have used this lower so let me execute the program yeah it's Anand mahajan a and amber capital but they have been converted into lowercase and whatever letters were in lowercase they will remain as it is now in the same manner we people can use the upper function which will do exactly the reverse it will convert your string into uppercase okay let me execute the program run okay yeah the whole string has been converted into uppercase so the output is Anand mahajan in capital letters. 

loader
Course content