0% found this document useful (0 votes)
17 views

Variable

Uploaded by

Ashish Rajput
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Variable

Uploaded by

Ashish Rajput
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Hello and welcome to this lecture and in this lecture you are going to learn something

about Variable.

So if you remember from school you had the subject which was called algebra and and the
subject we used

to have some mathematical expressions or algebraic expressions like A plus B c or x plus y


words 70

or something like that.

So if you recall from that class you might know that x y ABC and all the other things were
actually

called as variable

So variables in Python are exactly similar to the variables in algebra.

So essentially a variable is nothing but something which allows us to store a certain value.

So in the previous lectures we learnt about a lot of things but variables are actually one of
the most

important things in any programming languages.

Not only in Python because every program is nothing but something which actually takes
the data processes

it and finally puts out a result by manipulating that data are those numbers.

So essentially what we need to do is that we need to have something which allows us to


capture the data

or store the data and variables are the things which allows us to do exactly the same thing
which is

to see the data.

So without wasting any time let's go ahead and learn what are variables so let's make a
simple variable

so variable could have any name.

So let's name this variable a.

And let's say you want to see a value like 10 into .

So what you need to do is that you need to use that equal to sign this equal to sign and
Python as known

as the assignment operator.


So the main function of this assignment operator is to assign a value to the variable which is
expressed

to the left of it.

So on the left hand side we have a.

So in this case we want to assign a value 10 to a.

So we type a equal ten and when we do that the value of 10 is going to get stored in a.

And if you don't believe me then let's go ahead and print out the value of the variable.

So if we type in print and in the brackets if we specify a and hit enter.

As you could see the value gets printed out to be 10.

Now let's take another variable b and let's assign a value of 20 to it.

So if we assign a value of 20 to variable b.

This means the value of 20 gets stored in the variable b.

So again if you want to check if the value is actually stored you could simply print out the
content

of B.

So if we hit enter as you would see we got the result 20.

Now what you could do is that you could have a 3rd variable c

And you would simply say that c equal to a plus b so what this is going to do is that it is
going to take

a which is 10 then it is going to take b which is 20 it is going to add them up as a plus B


which

is going to be 30.

And finally the value 30 gets stored in the variable C

So if we execute this thing now the value 30 gets stored in C..

So if you want to check it by yourself you could simply type and print and you could pass in
a value

of c to print.

And if we actually print out the value as you could see you have the value of 30 within c.

And also one more thing which I would like to mention about variable is that you can not
only store numbers
into variables but you will also store names.

So you could simply type a equals and you type in your name here so I'm going to type in
my name and

if you hit enter the name actually gets stored in the variable.

But the only thing which you need to remember is that when you actually want to store a
value of name

to a particular variable or if you want to store a string into a variable you always mention
the string

in either single quotes or double quotes.

So in this case I mentioned my name and course and word this thing does is that tells
Python that we

actually want to store a string into a variable.

So if you again print out the value of it as you could see I'm going to get my name and
you're going

to get yours because you actually store your name into the variable.

Now what if you actually want to remove particular variables.

So let's see if you want to remove what is stored in this area.

So in that case what you could do is that you could go ahead and delete it by using the
delete statement.

So you could simply type in the del space and then specify from which particular variable
you want to delete

the data.

So in this case as we have a single variable.

So simply Daubeny and hit enter and the data which was stored in the video will now be
completely removed.

So if you want to make sure that the data is removed you could type and print and now this
time if you

pass the value of the variable as you could see it sees that name is not defined.

That is because we have deleted the value which was stored in a.

So that's it for this lecture.


And I hope you guys understood what are variables and how variables can be used to store
some data which

could be the numbers or strings or sentences so you could actually stored sentences and
variables as

well in the form of a string.

So that's it for this lecture.

And in the next lecture you are going to learn something about the emplace operators.

So thank you very much for watching and I'll see you guys next time.

Thank you.

You might also like