#9 Python Tutorial for Beginners | More on Variables in Python

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] welcome back aliens my name is Devin 20 and let's cut it up this series on Python and in this video we're going to talk about variable what hold on we have talked about variables right we know how to get variables how to assign values and you can change the value as well then why I get a next video now in this video we'll pop it in a different way you know we'll talk about more about memory consumption and what happens when you create multiple variables so let's get started you know let's in the flow itself we'll talk about what consider discus so we have our addicted ready and let's get started so let's start with some questions you know so I would ask your question you have to answer maybe in your mind or in the comment section your choice so now we'll do here is let me create a small variable I will say the variable name is num and the value for num is equal to 5 now what do you think what is happening behind the scene I can just imagine so there will be so in your in your memory or in your internal memory of your system you might be getting a box there with the name num and it will be having it own address right and the in that box will be having a value which is 5 so we kind of box in that we have a value 5 and it will be having a name and the address ok that's good so name is dumb and addresses something let's see what is the address how do you know what is the address now of course everybody will have it will be having some address right if you want to get the address what you will do is you will use a function name called as ID and then in the bracket you have to pass the variable name which is num so in this case if I pass num you can see we got the address out that's great so we call this is our address now this is possible with any type of variable ok you can go with string as well let's try so I will use our name equal to so let's say my name I would say now bean and again the same thing I will use an ID and in this I will pass name and you can see we got the address now for now we have a different address for ID we have a different time for name we have a different address that's great ok now think about this what if I create one more variable let's go with a different variable now I will say variable E and the value for a is let's say 10 ok so we have 10 and then we have value very variable B and B is equal to a now sign a to be yes the answer is yes you can assign the value of a to P now what do you think what is happening behind the scenes so how many variables we have how many boxes we have think about this maybe we should be having two boxes right one for a and one for B right so two boxes each box will have a value which is 10 and they might be having different address right of course if you have a different box you will be having a different address let's verify so first I will verify the values of it so I will type a we got 10 I will type B record 10 so both are the same value okay I will try to fix the address of a okay we called the address doesn't matter doesn't matter what's the address here some Vietnam BRR and I will try to add get the address of B oh that's weird we got the same address so in Python what happens is whenever you create multiple variables and in case if they have the same data they both will point to the same box they will not be getting multiple or the multiple boxes for for each variable and that's where Python is more memory efficient right because you're not getting multiple data here that's great so what what happens when I change the let's see let's see the ID of 10 okay we can also do that because everything which you are using here it is also called as object so in this case we have 10 which is an object name is an object five is an object I know you're thinking about objects now don't worry we'll talk about objects later in detail you can tell that point you can imagine object is a box okay so it is something where you can hold your data it sound like somewhat like variables but we'll discuss that indeed in detail later at this point everything is an object right there is an object here so every object will have an ID here so I will say enter and you can see we got the same ID so the actress is not based on the variable name it is based on the box itself so moment you say I want to use a value it belongs to a box and the address of that box is here now in future if you kid one more video but call us okay and if you assign the value for K as 10 now if I fetch the ID for K so we are not actually talking about K here we're talking about 10 because indirectly your K is referring to 10 right that's important so this variables are also kind of tags because we are tagging them so 10 is a value and your tagging a B K so everything is tagging the same same object okay this is this is awesome so you can see we got the same ID now if I change the value for a let's try so I will say a is equal to let's say 9 I want to change the value for a now what do you think will it affect the address of a of course right because now you have a different box different value different box and different box mean different address let's try and that's why we got a different value for a that works what so if I change the value of a and if you see this statement here this is simply B is equal to a right so if a changes will it affect B let's try ok so if I say ID of B but no so idea of idea of B is still the same old value because Abby is still referring to 10 right so we got two different objects two different boxes and each box are different address so here K and B is pointing to 10 and you're a is pointing to 9 now maybe in future you will say K is equal to a now so of course the tag of Kaiba changed to divide your 9 right let's verify so I will say int of K and you can see now just referring to 9 that's awesome ok so now we got two boxes right now what if you so V so you can see we have B which is referring to 10 as of now and K and elfing to 9 what if in future even B is referring to a new value let's say 8 so in total we have three boxes now so it is referring a and K they are referring to 9 and we have been deferring to 8 and no is referring to 10 now what will happen to 10 now 10 is dead right then is there in the memory and no one is using it and that's where India in Python we have a concept of garbage collection I can we'll talk about that later how it works so we'll talk about a PBM weight later so we have a different concept you know we have P a VM or chase garbage collection so we talked about those things in detail later but as of now remember this thing whenever you have a data in your memory which will not be used or which is not tagged by any variable it will be garbage collected later okay but did that point him if you have any reference it is dead in the memory okay it will be dead for for you for your use now how about creating a constant example let's say you know we have this concept of constants what are constants now so when you say variable it means you can change the value right now but when it comes to constant that means you cannot change the value but something like immutable stuff but can you make a variable constant and C programming is the only place where you can make a variable constant right but in Python you cannot do that yes you can show your intention by saying hey this is the constant example normally when we say constant we use a different format of names example capital letters so I will say PI value now if you remember in if you in maths we use a concept of pi of like 3.14 yeah now this is a constant value right no one can change it it will never be changed so in this case you will be using this as a constant of course you cannot stop anyone by changing this value example I can change this value later so if I type P I you can see we got a 3.14 but what if I change the value yes I can change the value I can say to the point 1 5 which will be a crime in this case but you know we can change the value but you can show your intentions by saying hey this is the PI this is you can see capital it was there so don't change the value this so the intention here is to make it constant don't change it so yes unfortunately in Python you cannot make it constant but but you can show your intentions now with variables we have one more concept which is called as type of the variable example in this case if I say the type now how do we know the type so we have this methodist type and you can pass by and you can see the type of pi is float so any one whenever you want to know the type of variable you just type type and in fact you can mention the variable name it will give you the type of it you can do the same thing for a BK and everything so with a venom I which we are using here those variables has a type which is in many types right but can I create my own types and the answer is yes you can create but we'll be doing that later you know it's some may be in some other tutorial but we can use inbuilt types example int float those are in place types but how many times we have normally these types are called as data type so we have some inbuilt data types and we are going to see that in the next video so in the next video we'll talk about different intellects and how to use it so I hope you are enjoying this series let me know in the comments section and that's it bye bye you
Info
Channel: Telusko
Views: 1,276,997
Rating: undefined out of 5
Keywords: python, navin, reddy, java, tutorial, telusko, variable, declare, define, call, assign, id, value, same, object, tags, tag, garbage collection, constants, type
Id: _OZIAHg5i7M
Channel Id: undefined
Length: 9min 12sec (552 seconds)
Published: Wed Jul 04 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.