Variables:
A variable is a name given to a memory location used to store data. In Python, variables are created automatically when you assign a value to them. For e.g.
x = 10
name = “Rahul”
price = 99.5
Here:
x is a reference to memory where 10 is stored
name is a reference to memory where “Rahul” is stored
price is a reference to memory where 99.5 is stored.
The words x, name and price are variable names which are in a way names internally given to memory locations where the given values are stored.
Variable names must follow certain rules, which we will study later in Identifier Naming Conventions. For the time being, just remember that variable names should be meaningful and related to the data or values they represent.
In the above example the values on the right side are called literals as explained in the article on “Tokens”. Some time these are also called “literal constants”.
Apart from literals, there is another category called constants, which is explained below.
Constants
In python constants are by convention only. The purpose of constants is to define values that are not supposed to be changed anywhere during the program. for e.g.
PI=3.1416
MAX_MARKS=100
I do not want that value of PI or MAX_MARKS once defined shall change anywhere in the program. Some languages like C++ etc. give a way to define it with a keyword const and make sure that the value can not be changes. In python by convention such names are defined with capital letters to indicate that they are constants. There value can be changed but it is programmers responsibility to make sure that they are not changed for proper results.