Variables and Assignment
Hello friends, Welcome to our website. Today we will talk about Variables and Assignment in Python.
marks = 70
marks = 70
As you can see, we just assigned the value of the numeric type to an identifier name and Python created the variable of the type similar to the type of value assigned. In short, after the above statement, we can say that marks is a numeric variable.
So, creating variables was just that simple only? Yes, you are right. In Python, to create a variable, just assign to its name the value of the appropriate type. For example, to create a variable namely Student to hold student's name and variable age to hold student's age, you just need to write to somewhat similar to what shown below :
Student = 'Jacob'
Age = 16
Python will internally create labels referring to these values as shown below :
Student ➡️➡️ 'Jacob'
Age➡️➡️ 16
Isn't it simple ?? ☺️Okay, lets now create some more variables,
Roll No = 21 ⋕variable created of numeric(integer) type
TrainNo = '11897' ⋕variable created of string type
balance = 2567.09 ⋕variable created of numeric(Float) type
Same way, you can create as many variables as you need for your program.
So with this we end with this Post. And in the next post, we will talk about Multiple Assignment in the next Post, so Follow our website to get the latest Post updates of Python Programming Language.
As you can see, we just assigned the value of the numeric type to an identifier name and Python created the variable of the type similar to the type of value assigned. In short, after the above statement, we can say that marks is a numeric variable.
So, creating variables was just that simple only? Yes, you are right. In Python, to create a variable, just assign to its name the value of the appropriate type. For example, to create a variable namely Student to hold student's name and variable age to hold student's age, you just need to write to somewhat similar to what shown below :
Student = 'Jacob'
Age = 16
Python will internally create labels referring to these values as shown below :
Student ➡️➡️ 'Jacob'
Age➡️➡️ 16
Isn't it simple ?? ☺️Okay, lets now create some more variables,
Roll No = 21 ⋕variable created of numeric(integer) type
TrainNo = '11897' ⋕variable created of string type
balance = 2567.09 ⋕variable created of numeric(Float) type
Same way, you can create as many variables as you need for your program.
Lvalues and Rvalues
Broadly Lvalues and Rvalues can be thought of as :
Lvalue: an expression that can come on the LHS(Left Hand Side) of an assignment.
Rvalue: an expression that can come on the RHS(Right Hand Side) of an assignment.
For example, you can say that,
a = 20
b = 10
But you cannot say,
20 = a
10 = b
a*2 = b
The above variables will give you an error.
The literals or the expression that evaluates a value cannot come on the RHS of an assignment hence they are Rvalues but variables names can come on LHS of an assignment, they are Lvalues. Lvalues can come on LHS as well as RHS of an assignment.
So with this we end with this Post. And in the next post, we will talk about Multiple Assignment in the next Post, so Follow our website to get the latest Post updates of Python Programming Language.
JAI HIND!!!
VANDE MATARAM!!!!!
No comments:
Post a Comment
If you have any doubts, please do let me Know.