Followers

Tuesday, December 24, 2019

Variables and Assignment

Variables and Assignment 


Hello friends, Welcome to our website. Today we will talk about Variables and Assignment in Python. 

A variable in Python represents named location that refers to value and whose values can be used and processed during program run. For instance, to store the name of a student and marks of a student during a program run, we require some labels to refer to these marks so that these can be distinguished easily. Variables called as Symbolic Variables, serve the purpose. The variables are called symbolic variables because these are named labels. for instance, the following statements create variables namely marks of Numeric type:
       
         marks = 70

Creating a variable 
 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. 


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.