#10 Python Tutorial for Beginners | Data Types in Python

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] welcome back aliens my name is 720 and let's continue this series of Python and in this video we'll talk about one of my favorite topic which is called as data types now why it's so important because we have worked with variables right everything was working now when you work on a project it's very important to understand whatever data you are working with so that you can process that data in that format because if you don't process the data in that particular format you might face others or maybe bugs and trust me bugs are horrifying so whatever data types we have here so this is these those things here the first one is none second one is numeric the third one we have is least double set string range and map electron coitus dictionary let me start with the first one the first one is none know what it means now when you have a variable and if that variable is not assigned with any value it is it is none normally in other languages we use a keyword as null but in Python we use none the second one is numeric type now if we talk about pneumatic we have multiple types here in fact we can go with four the first one is int then we have float then we have complex and we have bull so when you talk about numeric it works numbers right example when I say num is equal to 2.5 now this is float okay so float value now how do we know that this is float in fact in the last session we have done that right so we can use a type as a function and in this you can pass num and if you can say it says plus float again we talked about class later okay what class means but time beam it's a float okay so now I will say another number I will say num is equal to 5 of course we can change the type of variable right so now if I assigned 5 if I say num and you can see that to us now change to 8 that means the type of this num is 8 we also have complex right now what complex means so if I will say num is equal to now if remember mathematics we have used to have this concept of complex numbers right now how do you represent from this number so we used to say a plus B J or in fact it was I in complex but here we have to use J now we can replace the value of a with a number oh it's a six plus maybe nine J now my this j is represented by a square root of minus one okay now so let's say enter you can see it is it is accepting the value and if I see the type of this num its your complex type so complex basically means you have a number plus a plus or minus imaginary number okay now this works so we have ain't we have float and we have complex so can I convert from a different type example our value which is float and I want to convert that into integer is it possible let's try so what I do here is I will take a variable called as a and the value in a I will assign as five point six I have another variable which is B and I want to assign the int value of a can I convert it because if I see the type of eights float right I want to I want to get the type of B as eight and I want only I want to have the value which is five so in that case you will be using a int function in which you'll pass a so this int function will convert your float value or any value into integer format and that works now if I say the type of be it's int and the value of B is five right so we can convert that can I convert into value in to float yes we can so let's say we have another variable which is K and I want to fetch the value of B but not in the ain't format I want to I want in fluid format yes we can do that so I can say float and in this bracket you can pass it and you will get so if I say K you can see we got 5.0 and of course the type of it is float you can they can check it out later can I convert a normal number to complex number example I have a variable and I have B variable so I'm going to change the value for K and I will send the K to six okay so we got B as 5 and K as sex now I want to be the complex number so I will say C is equal to how do we get a complex number it's very simple just use a complex function at the way we are doing and then you can pass two variables here only one parameter that when that works if I want to pass two parameters I can pass B comma K and if I say C you can see the value now so it says five plus six j because 5 is your B and 6 is your K okay so it works so we can convert the value from you know here too that in fact we we can we can work with spring as well but we'll see that later now we also have a type Alice bull which is also as boolean now how can we use a boolean boolean value here now when it comes to boolean it simply means true and false now think about this computer world right all in this void we always take decisions and decisions are based on true or false I know V in your mind we always work with his conditions example let's say if you have two choices you will select those choice which is more favorable or which will be more profitable right so we apply conditions there so if that is more profitable we'll go there if this is more profitable it will go here then the same way we apply a condition and we get true or false so that true or false comes under boolean type if now we have B and K right so if I want to check if B is less than K we can do that so less than symbol is less than and if I say enter you can see we call true so true here is a boolean type right and you can assign that to a variable as well so I will say variable type as bull is equal to B less than k now you can see in this bull if I type bull you can see it is true and if I say the type of bull is what it felt because it's a type name as well right so I should be I should have used a different name here right so that's boolean for you in fact we have true and we have false as well example if I say B is greater than K and that's not the case right B is 5 K is 6 so it should give you false so we have true and we have false again their different operators which we can use less than get then so we have different operators which we'll discuss in the upcoming videos but here we can use true or false but then why I am keeping true and false in a numeric it should be different right the thing is in Python what we do is we we used true as 1 and false as 0 example it's a family if I want to convert true into a number you can say I'm converting then 2 into in Fermat and you can see we got one the same thing if I do for false you can see the called 0 so if true is 1 and false is 0 so that's your integer format you know that's your numeric type so we have talked about none we have talked about numeric the next that we have is in fact we have discussed those names right those things comes under sequence so when you said laced range set tuple those things comes under sequence now we have worked with Lynch before right so how do we define this is very simple you will say LST will show you can you find least here so I can say 25 comma 6 comma 45 comma 12 any number any number any format has a matter you can take string as well so you think this is how you work with lace and how do we know the type of it so it's a type of LST and you can see it says it is of type list the same thing will be done which said so if I could have set here I will say s equal to and you will use a color back edge there and inside that you can specify values so these values and you can see if I say enter and if I say yes you got the values there and you can see it is not repeating and if I defined the type of this s it is set right so even this works now the another type we have is tuple which we have worked with again so it's a t is equal to so we have to use a down packet here also 25 26 you can use any format doesn't matter right you can see record t and if I say type of T here is stupid okay now we also have a string type right so how do we define a string type it's very simple you say STR is equal to and you can specify a name here using double quotes or single quotes both works I can say my name that that's Naveen and using using STR you can perform certain operations again we have done that in detail in the in earlier videos right so if you want to know more about lists and tuples you can go back to the previous because then you can watch it in this video just we are just talking about the data data types available how about character because we have not talked about character right and if you are coming from some other languages like Java C C++ we do have a can type there now in Python we don't have a karyotype what we have is if you are creating a string let's say I will say this is st is equal to and if you have a single digit or single character that's a guy type for you but actually it is string because even if you say type and if you specify st you can see this it says plus str which is string in this case so we have string we don't have care as to be specific but we can use care as a part of string now we have another fancy stuff which is which is there in python but in other languages called as range example you know when you iterate or what his equation means going from one right to that the end by the example from 1 to 10 or 10 200 or maybe from 1 mm so when we iterate between values we can use a range how do we define range it's very simple you say range and you give 30 back it's a specific arranged example I want to I want to go till 10 so we go on the range from 0 and we have 10 values which is 0 to 9 how do we know which what values we have so what we can do is we can actually convert the ranging to at least so that we can print it right so what I will do is I will say list of range and we'll say 10 in fact there is another way of doing this we can also use a for loop but unfortunately we have not done that yet so we'll not be focusing on for loop here because we have a better way of printing it but as of now just to get the output of the range I'm converting a range into at least so that it can see the output and you can see this is a list of this is the range so if I want to get at least off let's say 10 values from 0 to 9 we will use as range there okay me you might be saying what if I want to have a range with different iterations maybe a different difference example I want to print all all all even numbers from 1 to 10 in that case you can do that you can say I want to have I want to start with fur maybe you can start with 2 and then you the ending part is 10 and the difference would be 2 because you want even numbers right so you can do that but you have to put that in a range range does take 3 parameter as well and you can see we got 2 4 6 and 8 so should I should happen till 11 right because that's the ending part okay so this is how you can use a range in fact you can just type here and you can say range of course right it will give you range as you can it will give you range type so that's one type you can use and all these things comes under sequence right because we are getting a sequence of values and now we have one of the most exciting type which is called that as mapping or you can say dictionary now this dictionary normally what happens you know when you have huge amount of data and even when you want to fetch data in efficient way or in a fast way you can what you can do is with every value you can assign a key normally English what we do is for the value we assign a index number right but in dictionary for every value we'll assign a key example let's say I want to have all the mobile phones names example so let's say in my friend group if I have let's say 50 phones everyone will imagine everyone has a different phone here so we can of course we can do index number right so index number zero iPhone 6s index number one samsung maybe samsung j8 index number three one plus three index number four let's say my five so we want to have all these numbers and I stopped having index numbers we can use a key which is your name example who has one plus three let's say Kiran who has iPhone 6s let's say the aqwal who has Samsung lexan I mean so in this case every mobile phone has a name or a key attached to it so it will be easier for you to fetch right okay now it's not just about string okay you can also use numbers you can also use example do olympos example when you go for giving your city exams or interest exams you get a number right that's your key so you can identify each object with a key how do I do that here oh there's one thing to remember key should be unique so if you have a dictionary all the keys has to be unique and values you can repeat values let's try it out how do we define a dictionary it's very simple let's say D is equal to you have to use a paddy packets now why Pat the packets because keys should not repeat and what does not repeat said and said to users cut the packets right so it makes more sense here so I will use a key as let's say Naveen can then I will use a value let's say Naveen has a phone which is Samson we can give another value by giving a comma and here I will say who has this value let's say Rahul Rahul is using let's I phone and then we have one more that's a killin and Kiran is using oneness okay now this is oh I made a mistake there okay so so I just missed a colon here right so that that was my bad if I try to print D you can see we got the key and a value pair so in this case now in Rahul and killing those are keys how do I know with those are keys you can say D dot you can print the keys and you can see record these keys you got Naveen Rahul and keyed on those are keys and if you want to get the values I guess we have added methods values yes we have do we do have a metal use values and if I Center you can see Samsung iPhone and wonders those are values now how do I get a particular value let's say I want to get iPhone here in this case I have to use a key right which is often in this case so I will say deep square bracket if we enlist we use index numbers right we don't have index numbers here we have a key so we'll use Rahul as a key and it's the enter you can see regard iPhone so that's dictionary in fact we have one more way of fetching value instead of using a square bracket we can also use function like get in this gate you can mention hey I want to fetch let's say Killins phone which is wonders right so you can use a square bracket you can use a get method everything works that's how you work with it a type so we have different types let me just lease those things once again so we have none we have numeric types we have sequence in sequence we have least range set tuple and then we have mapping in which we have dictionary so I hope it makes sense so in if you have any question let me know in the comment section and do clear like button if you're enjoying these sessions you
Info
Channel: Telusko
Views: 1,545,614
Rating: undefined out of 5
Keywords: telusko, navin, reddy, tutorial, java, python, data types, int, float, dictionary, mapping, range, numeric, double, complex, bool, tuple, list, string, example
Id: gCCVsvgR2KU
Channel Id: undefined
Length: 14min 35sec (875 seconds)
Published: Thu Jul 05 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.