Podcast Lookup

_4 Python Tutorial for Beginners _ Variables in Python

Python To You

  • October 10, 2026
  • 10 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.

_4 Python Tutorial for Beginners _ Variables in Python

00:00—
  1. Speaker 1

    Welcome back Aliens, my name is Dhavan Reddy and let's continue with this series on Python. In fact, in the earlier videos, we have talked about what is Python, we have installed two softwares and we have also worked with certain operations, right? We had fun in the last session. Now, in this video, we are going to talk about what is variable. But first of all, why do we need one? Let's try something here. So what I will do is I will go back to my previous example, you know, we were adding two and three. So we have done with that, right? We are saying two plus three. Now, if you remember in maths, what we do is we of course, we work with numbers. But then the moment you start with algebra, you have this concept of using X and Y. So what we do is we say let X is equal to five. Can we do that here? So we have X equal to two.

  2. Speaker 2

    So I'm storing this.

  3. Speaker 1

    Value two in a variable called X. And that's a new word now. What is variable? So basically variable is a container where you can put your values. Example, we are storing two here in a container and the name of that container is X. Of course, you can give any name doesn't matter. You can say ABC, you can say a box, you can give any name, right? So we can say X equal to two. And the moment I say enter, now this is the first time when you said enter and you have not got any output, right? So in the earlier prompts, what we did is when we said any, any operation, it was giving you some output. Here we have not got any output. It's just an assignment operation. So in assignment what we do is we have a variable name equal to a value. So we are assigning 2 to x. Okay that works. So can I do this now? Can I say x plus 3? Yes right because in x we have a value which is 2.

  4. Speaker 2

    Oh it works. You can see we got 5. That works. Can I store 3 as well? Let's try.

  5. Speaker 1

    So I will say y is equal to 3. Now we have two variables x and y. So we have two boxes. And now I will say X plus Y.

  6. Speaker 2

    Oh, it works, right? It works.

  7. Speaker 1

    So we can say X has two, Y has three, and we are adding them. Okay, so that's why we can we can use them. But then why they are called as variables. Now, normally, when you say variable, this term simply means you can change the value.

  8. Speaker 2

    Can we change here?

  9. Speaker 1

    Can I say X equal to nine? Can I change the value from two to nine? Let's try. And when I say enter, oh, it works. There was no error. But now if I try to do this, if I say X plus Y, X will have a value which is 2 or 9. That's a question because we are changing it, but there's no error.

  10. Speaker 2

    Enter. Oh, you got 12.

  11. Speaker 1

    That means the value of X now is 9. OK, so we can change the value and now we can justify that word as variables.

  12. Speaker 2

    Right. So what is variable?

  13. Speaker 1

    It's a box where you can have a value. Now do we need to define the type of the variable? You don't need to.

  14. Speaker 2

    So the moment I assign.

  15. Speaker 1

    A value, it automatically detects what type of value you are assigning.

  16. Speaker 2

    So in this case, it is integer.

  17. Speaker 1

    Now let's do this thing. What if I say x and if I say enter, what it will do? So the moment you say x and enter it will print the value of x in this case which is 9 right. What if I use a variable abc now of course we have not defined this variable right and we are still trying to use it. Now when I say enter you got an error the error is it says name error abc name abc is not defined and that's why we have not defined abc yet. So if you are if you are using a variable which is not defined so it will of course give you an error. Now, I will do one more thing. I will say X plus 10. So, of course, it will give you 19. Now, what if I want to add 19 with Y? I mean something in this way. I would say 19 plus Y. But then if you think about this 19, this is the output of the previous operation, right? Now, if you want to use the output of the previous operation, we can use underscore. So, underscore represents the output of the previous operation. And if I say enter, you can see we got 22. So, it is 19 plus 3, which is 22. So even this works, right? So this is amazing. You know, there are so many things you can you can work with this. So we can use variables for numbers, right? So we can use it for float or integer. What about string? Can I use names with can I use variables with string or a string variable?

  18. Speaker 2

    Let's try.

  19. Speaker 1

    So I will get a variable as name and I will use a name as YouTube. And if I say enter, oh, it works. And if I print name, we got YouTube. So it is perfectly working. so we can use string as well so example i can say name plus youtube rocks so you can you can see we got youtube rock so it is name which is youtube plus rocks okay this even this work that's perfectly fine in fact let me just do an experiment can i say name and space rocks okay this is not working so we have to make sure that you put plus there because if you have plus then then only it will try to interpret that But there's this one thing which is very fancy here, you know. So we talk about YouTube.

  20. Speaker 2

    It's a string, right?

  21. Speaker 1

    And it's a combination of characters. That means if I want to fetch one character, it should be able. We should be able to do that, right? And yes, we can do that.

  22. Speaker 2

    So if I say.

  23. Speaker 1

    Name and if I want to fetch one character, how would I do that? So let's say if I have a YouTube here. And YouTube has seven letters or seven characters. If you when you break it down, it will create an array or you can say collection of characters. The numbering starts with zero because normally in computers, numbering always starts with zero. So here, if you want to fetch it, we have to use a square bracket and you have to mention zero. So we are specifying, hey, I want to fetch the first letter of name.

  24. Speaker 2

    So in this case, it is Y. How it works?

  25. Speaker 1

    So now I will fetch the last one, which is six, which is E in this case.

  26. Speaker 2

    We got E. That works.

  27. Speaker 1

    Now I will fetch, let's say eight. See, we don't have eight. We don't have nine characters, right? We only have seven characters. So the first one is zero. The last one is six. How about eight? The moment you do that, it will give you an error. It says zero. Index error string index out of range. So of course you're going out of your limit, right? So you cannot do that Okay, can I use negative numbers? Let's try I will use minus one So I want to I want your guess here what you think it will what it.

  28. Speaker 2

    Will do Come on. Think about it.

  29. Speaker 1

    Okay, so let me just enter it and let's see what happens So when I say enter you got e okay, so the answer is when you say minus number it will start from right to left and OK, so it will it will start with the ending.

  30. Speaker 2

    So which is E in this case?

  31. Speaker 1

    That means if I say minus two, it will give you the second last data, which is B.

  32. Speaker 2

    That's right.

  33. Speaker 1

    And if I say minus seven, which will be the first one, right, which is Y.

  34. Speaker 2

    Oh, it works.

  35. Speaker 1

    It goes in reverse order now. Now, what if I want to print two characters, not one, two? So let's say I want to print Y and O. So in this case, I will say name and I will start with zero. Of course, we want to print zero, the first character and the second character, right? That means we will give two. Now, this two doesn't mean number of characters. It means the ending. So I want to start with zero and one. So first two characters. And you can see we got Y zero. the same thing if i do it for one colon four so come on guess so one means second character right so it will start with o and it will end at three because you cannot include four so it will it is exclusive of four uh so it is one which is o u and t oh it works we got out yes yes out it works Now, what if I specify only one and colon? If I don't specify the ending, what happens? In this case, it will start with one and it will go till the end. Okay, that how it works. So, if you don't specify the ending part, it will go in that way. What if I specify the ending part but not the starting point? Example, if I say, if I keep it blank and after colon, I will say four. Now, in this case, it will start with the first letter and it will end at three, which is before four. And that's why you got Y-O-U-T. So this is fun, right? Okay, what else we can do here? What if I specify name and I will give wrong values. I will say 3 colon 10. Of course, we don't have 10 characters, right? Now, in this case, it will end at the last one, which is available. So it will not give you any error at this case.

  36. Speaker 2

    You can see we.

  37. Speaker 1

    Got T U B E tube starts with T and then it's end at E because we don't have any other characters.

  38. Speaker 2

    So if you don't, if you want to avoid errors, this is what this one way. Okay.

  39. Speaker 1

    Now can I change the later example? I don't want it to be YouTube. I want to, I want it to be my tube.

  40. Speaker 2

    So I will say name.

  41. Speaker 1

    From 0 to 3, I want to change this with my.

  42. Speaker 2

    Can I do that?

  43. Speaker 1

    So I'm changing YOU to my. The moment I say enter, you've got an error. It says string object does not support item assignment. So the thing is, once you assign the value, you cannot change it. Not even for one character. If I say 0, I want to change the first character to rawtube. Even this will not work. You can see we got the error. So you cannot change the value. That means strings in Python is immutable. You cannot change the value of it.

  44. Speaker 2

    That's awesome.

  45. Speaker 1

    Right. But then that doesn't mean you cannot you cannot change while printing. Example, if I if I want to print my tube, you can do that. So first I will print my and then I will give up. I will give a space and then plus I want to print tube.

  46. Speaker 2

    Right. So in that case, I will say three colon.

  47. Speaker 1

    6 or maybe the ending part doesn't matter so you can see we got my tube if you don't want space you can do that you can say my and then without space you can type it tube.

  48. Speaker 2

    So this works yeah so this is how.

  49. Speaker 1

    You work with string you work with variables right you can have a number of variables you can have a float variables and you can have a string variable as well in fact with string we have one more thing let's say if you define a string which is, let's say, my name is a variable and my name here is Naveen Reddy. And if I want to know the length of my name, we can do that. So we have a length function and we can pass my name. As I mentioned, there are some inbuilt functions available in Python and one of them is length. So you can see we got 11 characters.

  50. Speaker 2

    So that's it. That's it from this video where we have talked about different variables.

  51. Speaker 1

    Assignments and stuff. So I hope you are enjoying my session. Let me know in the comment section and do give me a like button if you're enjoying it.

  52. Speaker 2

    Thank you so much for watching everyone. Bye.