Variables in Python !
595K views
Feb 6, 2024
"Dive into the fundamentals of Python programming with our insightful tutorial: 'Variables in Python!' Uncover the building blocks of code as we explore the concept of variables in Python, discussing their types, usage, and the role they play in dynamic programming. Whether you're a coding beginner or looking to solidify your Python knowledge, this video provides a clear and concise guide to understanding how variables work in Python. Learn how to declare, assign values, and manipulate variables to harness the full power of this versatile programming language. Join us in this foundational exploration and take the first step toward mastering Python programming with confidence!"
View Video Transcript
0:00
Hey guys, welcome back to our second lecture of Python's Basics
0:11
And in this lecture, we'll be taking a look at the variables
0:17
What variables really are and how to work with them, right? What are they used for
0:25
So well, just a definition for you, a simple definition for you, a variable is a container
0:35
that you can use in your program to store data. Now what is that data
0:42
We'll discuss that in other lecture, in upcoming lecture. So data, well, it can be anything
0:50
And in Python, we have different types of data and that we would be discussing in upcoming lecture
1:00
But just keep in mind that variables are used to store data and each variable must have
1:13
a name. And when we use that name in our code, if we have defined a variable and it's holding
1:24
some data, and if we refer to that name, that variable's name, then the compiler will get
1:33
into that variable and it will check out what's that variable holding
1:39
And it will refer to that data, what is being saved in that variable
1:46
For instance, look, I have a variable, suppose a equals to 10, right
1:57
So this is a variable. I mean, this a right up here is my variable's name and it's holding 10, a number
2:09
So it's holding 10 and through this operator, which is the assignment operator, we can store
2:17
data in a variable. So if in the letter program, I mean, if I'm coding right here and if I refer to a or if
2:29
I want to work with 10, I can just simply type a and the compiler will know itself that
2:36
actually you're referring to this 10 because 10 is being saved in this variable, in a variable. Right
2:47
I hope this is clear. See, if I print out simply a, so it's going to print out 10 on the screen. Why
2:57
Because I refer to that variable and this variable is here holding 10
3:05
So it would print out 10. Want to give it a try
3:09
Let's do it, guys. Let's run this code and see what's going to happen
3:14
And you will see that we'll get 10 on the screen. So it's going to compile
3:22
And as you can see down here, guys, we got our result and that is exactly 10
3:28
So why it's happening? Do you get it? It's because a is holding a number which is 10
3:37
So a is holding 10. If I try to display that a, it will refer into that variable and will fetch that value
3:50
from the variable that we have specified here. And you can also print 10 like this
3:57
So we have the same result. See, the result, both of the outputs are same
4:06
But when we type a here, when we refer to that variable, it gets into that variable
4:15
and it fetches its value. So suppose if I change the value to 20, then it would print out 20
4:23
Let me show you. See, can you see that? Now it's printing, it's displaying 20 because I've modified the value for variable a
4:34
That's how things work, bro. Now I want to modify its value and keep it as 10
4:43
And what if I take another variable? Yes, you can have unlimited variables in your program
4:50
It doesn't matter. So suppose I have another variable b equals to 5
4:57
So if I print out b, what I'm going to get is, will be 5 on the screen
5:04
Let me show you. Did you see that? Now I got 5
5:10
It's because b variable is holding 5. Now let's do something else
5:20
I want to specify, I want to initialize another variable c equals to a plus b
5:32
Now can you see that? What's happening around here? a variable is holding 10, b variable is simply holding 5, and c variable is actually holding
5:46
the sum of both variables. Did you get it? I mean, a is holding 10 and b is holding 5, and the c variable is another variable and
5:59
that keeps the sum of both variables, that are a and b
6:04
So if I print out c here, which is the sum of a and b, I'll get 15 on the screen
6:12
Let me show you. Can you see that? I got 15. Why
6:17
Because the c variable has stored the sum of a and b
6:24
When I refer to c, it gets here, and it checks out that there are two more variables and
6:31
are being added. So when it comes down here, it gets into a and it gathers the 10, and when it goes to
6:41
b, it collects the 5. When that is being added, when we find out the sum, when the compiler finds its sum
6:51
then again it's being assigned to c, and that's how you print out c value
6:56
And that is why it's holding 15. Let me show you, let me prove it
7:01
What if I put 20? What if I put 20 here? What's going to happen
7:09
Did you see that? I get 30 because I've modified the value for b
7:14
That's how things work. You can also use a, you can also find the difference of a and b
7:23
So let me show you what I got. I got minus 10 because 10 minus 20 is always equal to minus 10
7:35
So you can have negative numbers either. Yeah, it's up to you
7:41
You can put a multiplication symbol here. You know this asterisk symbol is used for multiplication or you can say to find a product
7:51
So we get 200 right down here. It's 10 multiplied by 20
7:58
You can also divide it bro. Like let me check out. I get 0.5
8:09
So that's how we work with variables bro. And yeah, it's all up to you
8:16
Like you can add variables here as well. A plus B and then minus C. So what you're going to get
8:23
So this is an expression. Let me run this code and see what's going to happen
8:28
I'll get 29.5 because first addition is being done and then it subtracts the C value from it
8:39
Keep in mind that programming or I can say Python basically follows the board mass rules
8:47
you know, and I'm sure you know that, right? So that's why we get 29.5 right down here
8:54
That's how we work with variables and let me comment it out here and variables, variables
9:03
So these are variables. Is there still remains any question? If you have got to the comment section and ask your question freely, I'm going to answer you
9:18
So that was our second lecture, bro. That was our second lecture
9:23
And if you are here, then that really means that you are really fascinated by learning Python
9:31
So stay tuned, bro. In the next lecture, there's another topic associated, an important topic associated
9:39
with variables. So if you, if you take your time and watch that one, well, that was all for now
9:48
If you enjoyed this lecture or have you got something from it, consider giving it a thumbs
9:55
up and subscribe for more. Definitely. And I'll meet you in another one
10:03
Thank you for watching
#Computer Education
#Programming
#Scripting Languages