Basics of Strings

Lesson Details:
September 17, 2020

Video Transcription: In this lecture we are going to learn about a very important function of Python STR this video is brought to you by Appy Pie’s Academy, go to the project press the right mouse button and then we will go to new choose Python 5 as I told you in one project you can have as many Python files as you want give the name of this new file using as clear or something the extension py will be automatically so fixed so I'm going to declare a variable called name because I am going to give the value within quotation mark it will be treated as a string variable okay the name value of name variable is David that of ages 21 as you can see each variable bill will be treated as an integer variable because value is integer okay so in the print statement I am going to write name of imply plus name plus as you know is the concatenation symbol name of employee is equal to will be printed as it is and in front of it the value of name which is David will be printed again concatenation symbol and he is okay within double within double inverted commas that is quotation marks then plus age value of H is 21 so we will expect that result would be and he is 21 years old will be printed as this because of being within quotation marks so value of name is David here in place of this variable name the value David will be printed and he is being in the quotation marks will be printed as it is then the value of age will be printed and as you know in this case the value of age happens to be 21 and years old would be printed as it is the program seems to be quite simple but when I will try to execute it you will see it will give you an error message so the error would be because of this variable age which happens to be off int when we use plus concatenation symbol both the items should be of the same data type that is string so let's first execute the program yeah you can see type error can only concatenate STR means string not int two STR this error message says that the variable age is of integer datatype so it should be first converted into screen data type so for that a very simple function as TR is there in Python so when I would write STR age what would happen is age will be converted into string so on both the sides of the plus concatenation symbol the items should be of string type so that is why we had to convert age into string by using STR function so I am going to execute this program now the program will run perfectly okay yeah name of imply is equal to David and he is 21 years old now there is no error.

loader
Course content