- Podcasts
- Python To You
- _9 Python Tutorial for Beginners _ More on Variables in Python
_9 Python Tutorial for Beginners _ More on Variables in Python
Python To You
- October 12, 2026
- 9 min
About this episode
No description.
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
_9 Python Tutorial for Beginners _ More on Variables in Python
You know, we'll talk 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 concept we'll discuss. So we have our editor ready and let's get started. So let's start with some questions, you know, so I will ask you a question you have to answer, maybe in your mind or in the comment section, your choice. So what I will 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 five.
System, you might be getting a box there with the name num and it will be having its own address, right? And in that box, you will be having a value which is five. So we've got a box in that we have value five and it will be having a name and the address. Okay, that's good. So name is num and address is something. Let's see what is the address. Hey, how do you know what is the address? Now, of course, every variable 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.
And again the same thing I will use an id and in this I will pass name and you can see we got address now for num we have a different address for id we have a different for name we have a different address that's great okay now think about this what if I create one more variable let's go with a different variable now I will say variable a and the value for a is let's say 10 okay so we have 10 and then we have value variable b And B is equal to A. Now, can I assign A to B? Yes, the answer is yes. You can assign the value of A to B. 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.
We'll talk about objects later in detail. You can imagine that point. You can imagine object is a box. OK, so it is something where you can hold your data. Some like some somewhat like variable, but we'll discuss that in detail later. At this point, everything is an object, right? 10 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 address is not based on the variable name. It is based on the box itself. So the 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 get one more variable called K 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?
Okay, so if I say ID of B, oh no, so ID of B is still the same old value because B is still referring to 10, right? So we got two different boxes and each box has a different address. So here K and B is pointing to 10 and your A is pointing to 9 now. Maybe in future you will say K is equal to A now. So of course the tag of K will change to the value 9.
So I will say int of K and you can see now it is referring to 9. 9 that's awesome okay so now we got two boxes right now what if you so we so you can see we have b which is referring to 10 as of now and k and a referring 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 a is referring a and k they are referring to 9 and we have b referring to 8 and no one is referring to 10 now what will happen in 10.
And that's where in Python, we have a concept of garbage collection. Again, we'll talk about that later, how it works. So, we'll talk about PVM later. So, we have a different concept, you know, we have PVM, objects, garbage collection. So, we'll talk 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 till that point if you have any reference it is there in the memory okay it will be there 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. Something like immutable stuff. But can you make a variable constant? And see, programming is the only place where you can make a variable.
But in Python, you cannot do that. Yes, you can show your intention by saying, hey, this is a constant. Example, normally when we say constant, we use a different format of names. Example, capital letters. So, I will say pi value. Normally, if you remember, in maths, we use a concept of pi, 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 pi you can see we got 3.14 but what if i change the value yes i can change the value i can say 3.15 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 a pie. This is you can see capital letters there. So don't change the value. 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.
So we have this method called as type and you can pass pi and you can see the type of pi is float. So whenever you want to know the type of variable you just type type. and in bracket you can mention the variable name it will give you the type of it you can do the same thing for a b k and everything so with the variable which we are using here those variables has a type which is inbuilt 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 in some maybe in some other tutorial but we can use inbuilt types example int float those are inbuilt types but how many types we have Normally, these types are called as data types. 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 data types and how to use it. So I hope you're enjoying the series. Let me know in the comment section and that's it.
