hello everyone i am siddharthan in this video we are going to discuss about the basic data types in python actually i have made a video on this topic already but there was some lag in that video so i am recording this again in case you have watched that video already you can skip this one with that being said let's get started with today's video and as you might know in this youtube channel i'm making a hands on machine learning course with python and the second module of this course is python basics for machine learning and this is the third video in this second module so let's get started with today's video so i'll be doing my python programs in google collaboratory i have already made a video on how you can access google collaboratory so you can check that out so let's get started so these are the five data types in python okay so they are integer floating point complex boolean and string so these are the basic data types we know that integer is a real number right so integer are numerical values and floating points are decimal numbers and we know that complex number is something that has both real number and an imaginary number and boolean is nothing but true or false values so it contains only two type of values one is true and the other one is false and string is nothing but text or statements okay so these are the five basic data types in python apart from these basic data types we have other complex data types such as list tuples etc so we will discuss about that in a later video so these are the basic ones so let's get started and let's try to understand each of these basic data types first let's discuss about integers so in python you can write comments using you know this ash symbol okay so i'll make a comment here as integers okay so integers i'm going to create a variable as a okay so in the previous video with index 2.2 i have explained what is meant by variables so we are just declaring a variable here as c8 and a is equal to 8 and now let's try to print the cl we know that 8 is a integer right so let's print a so in order to run the cell you can press shift plus enter so it will execute the cell and go to the next one so you can see here we have printed a and it has printed eight because we have given the value for a as eight we know that eight is an integer right so let's say that in some cases you are not sure what is the data type of a particular variable in that case you can use the keyword type okay so type is a keyword in python which tells you the data type of a particular value here let's mention a in this parenthesis so this will return what is the data type of va okay so let's run this press shift plus enter okay here you can see here int which means in so in represent integer values right so this is how you can print integers values so you can give an integer value to a variable and you can print it now let's discuss about floating points so i'll make comment here as floating point and let's take the variable as b and let's give a value like 2.3 so we know that 2.3 is a decimal value so we know that floating points are nothing but decimal values and now let's try to print this b and let's also try to find the data type of b so type b okay so let's run this so you can see here 2.3 so we have printer b whose value is 2.3 and we have found the data type of b as float okay so short form for integer is in and for floating point it's float now let's discuss about the third data type which is complex numbers so complex numbers so we know that complex numbers has both a real term and imaginary term so let's name this variable as c and they'll give a complex number as one plus three j here uh one is the real term and j is the imaginary term so j square will be equal to minus one so that is meant by complex number where you know we can also use i so i or j is you know square of this j is equal to minus 1 that is the imaginary path and you can print c okay so let's also try to print the data type of c okay so this prints the complex number which is one plus three j and also it prints the data type of c which is complex so these are the first three basic data types in python as we have discussed about these three data types there is another interesting thing that we can do we can convert one data type to another okay so i'll mention a text here as conversion of one data type to another so here i'm going to convert two data types so let's try to convert an integer into a floating point and let's convert a floating point into one integer so this will be integer to float so let's name the variable as okay so i'll give some other variable name which is x so let's say that x is equal to 10 and let's try to print x first and let's also try to print the type of x the data type of x so i'll run this okay so you can see here we have printed x the value of x is 10 and it is an integer now let's try to convert this to a floating point so let's name this variable as y and to convert integer into a floating point we need to mention the keyword float and inside this parenthesis mention the term which you want to convert here x is an integer right and let's convert this x into a floating point so you need to put x in this parenthesis so this will convert okay one second so this will convert x to a floating point value and that floating point will be value will be stored to y and let us try to print both y and the data type of y so type y here you can see here now we get the value as 10.0 so we know that 10 is an integer and 10.0 is a floating point or decimal value and we have successfully converted this integer value using this keyword float and we have tried to type you know print the data type of y and it has printed float so this is how you can convert an integer to a floating point value now let's see how we can convert a floating point value to integer okay so float to in and i'll take the variable as x x in this case let's give some random floating point value 5.88 and let's print x and also the data type of x so type ex so the value of x is 5.88 and the data type is float now let's see how we can convert this so y is equal to so previously we have used this keyword float right in this case we are going to use the keyword int which will convert the value to an integer value so now mention x in this parenthesis okay so x and once we have converted it let's try to print y and also the data type of y so we can see here this 5.8 decimal value is now converted to an integer value which is 5 and we have found the data type as integer so that is one main thing which you need to take note of in in this case so when you convert this uh floating point into into an integer value it doesn't round the value it doesn't convert this 5.88 to 6 it just removes you know this decimal values and it will give only this integer value so this 5.88 won't be converted into six but this you know this 0.88 will be removed and we will get only five okay so this is what happens when you convert a floating point to an integer now uh we have the fourth data type which is boolean right so here i'll just mention a text as boolean so as i have told you earlier boolean has two values one is true and the second one is false so i'll mention it here true and false okay now let's create the variable as ca and let's put a is equal to true so this is a boolean value okay so there is another main thing here so this t should be in upper case letters so it shouldn't be in lower case letter so this will give us an error so this is a predefined uh value so it should be you know as such it is in this case so the t should be in upper case letter and let us try to print this a now so print a and let's try to print the data type of a as well so type of a sorry so type of a so this a is printed as true and we got the data type as so bolt represents a boolean okay so let's create another variable as b and b is equal to false and let's print b also the data type of b so you can see here so this is how you can you know assign a boolean value to a variable and you can print it and find the data type of it and the final thing which we have is string right so before that let's discuss one more thing about boolean so let's see where we can use these booleans so i'll create a variable as ca and let's say that a is equal to 8 is you know let's say that 7 is less than 3 so we are just you know checking whether 7 is less than 3 so you know that 7 is not less than 3 so this is this statement is actually a false one right so this will return a boolean value when you just compare two values so here we are checking whether it is less than three so we are checking whether seven is less than three when you run these kind of codes it will return a boolean value now you can try to print a okay so let's also try to print the data type of a okay sorry so p shouldn't be in upper case letter okay so you can see here 7 is not less than 3 so it will give a boolean value which is false and we have tried to print print the value of a which is false and we have also tried to find the data type of a so similarly i'll just copy this and let's change this symbol okay so let's say that 7 is greater than 3 and this condition is true right so let's call this as a condition so let's check whether this condition is true of course 7 is greater than 3 so this will return the value as true so let's see so yes so true and it is a boolean value so we use these kind of you know conditions in loops and in the case of if statements etc so in that cases we will get a boolean value so this is one main application of boolean data type and the final data type which we are going to discuss is string so strings are nothing but text and statements uh you know and let's try to print some statements so i'll print machine learning okay so machine learning is a string so these two words represents a string and let's try to print this so this will print you this string the main thing about the string is the strings should be enclosed in ports okay so here i have used double quotes right so instead you can also use single quotes so i'll just copy and paste this here and replace this double quotes with a single quote and i'll run this this will give you the same result okay so the main thing here is if you start with single quote it should end in uh you know single quotes as well if you start in double quotes it should end in double quotes as well so the code shouldn't change but you can use either double quotes or single quotes so let's discuss some basic operations in swings that we can use so i give a variable name here as my string okay so let's say that my string is equal to so as i have told you earlier strings should always be enclosed in codes whereas we don't have to enclose you know values this integer values and floating point values in quotes so only the strings should be enclosed in codes and here boolean is a different data type hence we do not enclose it in ports only the strings should be enclosed in codes either single quotes or double quotes and i will give the values the same machine learning and i'll print this my string here we have created the variable as my string and i am printing it let's try to find the data type using the type keyword this type function so my stream so let's run this now you can see here our string which is machine learning has been printed and we found the data type as string so str represents string and let's try another thing print hello and five okay so i'm using this symbol here this uh you know star symbol let's see what happens we know that this represents multiplication symbol in python right so when you use this line of code and let's try to print this what happens here is your string will be printed five times if you mention five so if you mention four your string will be repeated four times so this is uh how you can replicate your string using this line okay so now let's see how we can slice a string this process is called as slicing and just make a text here as slicing okay let's create a new string as let's name this variable as my string and let's give the value as programming so this word programming has totally 11 letters okay and i am going to slice this string slice means getting you know only a particular portion of this string this particular word so let's print my string but i don't want to print the entire thing i just want to print a part of this word and you can mention the values such as 1 is to 5 okay so let's understand indexing in python so indexing or the numbering in python starts with 0. so the index of this first letter p is zero and uh the index of the second letter r is one and two and so on so p will be zero r will be one z o will be two and so on so zero one two three four and it goes on and we can mention the letters based on their index so one means the second letter r right because the indexing starts with zero and one represents this second letter which is r and i want to print all the words from the first index r to the fifth index five let's see which is the fifth index so p is the zeroth one so r o g r e so ah zero one two three four and five so here is the index five so when you use uh this particular line one is to five the values from this first index 1 will be printed all the way to this fifth index but this fifth letter won't be printed this fifth index value which is va won't be printed so let's run this and try to understand this okay so we got the values as r o g r so this first index value will be printed which is r and this second index value phi won't be printer so you will get the values from r o g r so this second index value will be uh you know neglected so this is how you can slice a string so the main thing to note here is the first value up to the last value minus one so here the value should be printed so i'll just make a note here so the values from index 1 to 5 minus 1 so 5 minus 1 is 4 right so will be sliced will be sliced so in every indexing cases so this second index won't be included so that is what you need to take note of in this case and there is another process called a step so we can also you know slice the words having a step value here let's print my string and my string convention 0 to 10 let's take a step as 2 so i'm going to print from a zero so the zeroth index is p right all the way up to tenth index so tenth index is this yen so 10 to get you know tenth index is n and sorry one second so this is a zero one two three four five six seven eight nine ten so tenth index is g let's try to print this step so what happens when you mention uh two here is so p will be printed and r will be uh you know removed o will be printed g will be removed so that means uh you know step of two that means every second letter will be skipped let's try to run this okay so here you can see here the uh tenth index value is cn so as i have mentioned you here that the second index value won't be involved or it won't be included in this slicing so we will get the value from this 0 index to the index 9 and every second letter will be removed here when you take p as the 0th index the second letter r will be removed and we will get og will be removed and r will be printed and a will be removed and so on so this is how you can slice a string by mentioning the step which we want okay so there is another thing which you can do with string folders string concatenation string concatenation so concatenating is nothing but joining two strings so let's uh name this variable as word1 so let's give the value as word1 is equal to machine so i'm mentioning single quotes here and let's take the second value as word two so word two is equal to learning okay now i'm going to create another word so let's let's print this so print word one plus word two so when you use this plus symbol so these two words will be joined so this process is called as string concatenation so you can see here there is no space here right so you cannot get a space uh with you know when you mention this plus so if you want to have a space you can just mention a space here and let's run this so this will give a space between them so this is how you can concatenate or join two strings so these are some basic details of the data types in python and basic operations on the data types that we can do so i'll just give you a quick recap on what are the things we have done here so we have discussed the first you know the five basic data types in python which are integer floating point complex boolean and string we have tried to print uh we try to give you know give a value of integer to a variable a and we printed it and we have also tried to find the data type of a and then we have tried the same with a floating point value and we have also tried to create a complex number and then we have seen how we can convert one data type to another using their respective keyword so in this case we have used this float keyword to convert an integer value to float here we have used you know integer keyword to convert a floating point value to an integer and we have discussed about the two boolean values which are true and false and we have seen how we can use these boolean values in the case of conditions and then we have discussed about strings and how you can replicate the strings and how you can slice the string by mentioning their indexes and now you can slice a string by mentioning a step value and finally we have seen how we can you know concatenate two strings so these are some basic details about the data types in python and the next video which you want to watch will be on the other data types which are list tuples rs etc okay so that's it for this video and see you in the next video thanks for watching