Podcast Lookup

_9 Python Tutorial for Beginners _ More on Variables in Python

Python To You

  • October 12, 2026
  • 9 min
Episode page

About this episode

No description.

Transcript

From the publisher

This transcript comes from the podcast’s own feed, shown as the publisher wrote it.

_9 Python Tutorial for Beginners _ More on Variables in Python

00:00—
  1. Speaker 2

    Welcome back aliens.

  2. Speaker 1

    My name is Devyn Reddy and let's continue with this series on Python. And in this video, we're going to talk about variable. But hold on, we have talked about.

  3. Speaker 2

    Variables, right?

  4. Speaker 1

    We know how to get variables, how to assign values, and we can change the value as well.

  5. Speaker 2

    Then why again the next video? Now in this video, we'll talk in a different way.

  6. Speaker 1

    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.

  7. Speaker 2

    Now, what do you think? What is happening behind the scene? Just imagine. So there will be, so in your memory or in your internal memory of your.

  8. Speaker 1

    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.

  9. Speaker 2

    Oh, that's great.

  10. Speaker 1

    So we got this is our address. Now, this is possible with any type of variable. OK, you can go with string as well.

  11. Speaker 2

    Let's try. So I will use a name equal to. So let's say my name. I would say Naveen.

  12. Speaker 1

    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.

  13. Speaker 2

    Address, right? Of course, if you have a different box, you will be having a different address, right? Let's verify. So first I will verify the values of it.

  14. Speaker 1

    So I will type A. We got 10. I will type B. We got 10. So both have the same value.

  15. Speaker 2

    Okay.

  16. Speaker 1

    I will try to fetch the address of A.

  17. Speaker 2

    Okay. We got the address.

  18. Speaker 1

    Doesn't matter what is the address here. some weird number and I will try to get the address of B. Oh, that's weird.

  19. Speaker 2

    We got the same address.

  20. Speaker 1

    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 multiple boxes for for each variable. And that's where Python is more memory.

  21. Speaker 2

    Efficient, right? Because you're not getting multiple data here. That's great.

  22. Speaker 1

    So what what happens when I change the let's see, let's see the ID of 10. OK, we can also do that because everything which you are using here, it is also called an object.

  23. Speaker 2

    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.

  24. Speaker 1

    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?

  25. Speaker 2

    That's important. So these variables are also called tags because.

  26. Speaker 1

    We are tagging them. So 10 is a value and you're tagging A, B, K. So everything is tagging the same object. Okay, 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.

  27. Speaker 2

    Now, what do you think? Will it affect the address of A? Of course, right?

  28. Speaker 1

    Because now you have a different box, different value, different box and different box in different address.

  29. Speaker 2

    Let's try. And that's right. We got a different value for A. That works. What?

  30. Speaker 1

    So if I change the value of A and if you see this statement here, this is simply B is.

  31. Speaker 2

    Equal to A, right? So if A changes, will it affect B? Let's try.

  32. Speaker 1

    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.

  33. Speaker 2

    Let's verify.

  34. Speaker 1

    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.

  35. Speaker 2

    Now, 10 is there, right? 10 is there in the memory and no one is using it.

  36. Speaker 1

    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.

  37. Speaker 2

    Constant, right?

  38. Speaker 1

    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.

  39. Speaker 2

    Example in this case if I say the type. Now how do we know the type?

  40. Speaker 1

    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.

  41. Speaker 2

    Bye-bye.