Need of Variables

While programming, we very often need to access the memory to read and write data.

The memory addresses are hexadecimal values.

So, it is very hard to keep track of hexadecimal values while programming.

To manipulate memory address easily, we can attach a name to the memory address.

So, it will be very easy to make use of the memory address using a variable name rather than hexadecimal values.

Pictorial Explanation

variables in python

In the above diagram, memory address 22fe4c has been mapped with the variable name letter.

Using variable letter, we can easily manipulate the memory address 22fe4c.

Similarly, using variable letter2, we can easily manipulate the memory address 22fe4d.




Variable Naming Rules in Python

1. Variable name should start with letter(a-zA-Z) or underscore (_).

Valid

age

_age

Age

Invalid

1age


2.In variable name, no special characters allowed other than underscore (_).

Valid

_age

age_

Invalid

age_*

+age


3.Variables are case sensitive.

age and Age are different, since variable names are case sensitive.


4.Variable name can have numbers but not at the beginning.

Example

Age1

Age2


5.Variable name should not be a Python keyword.Keywords are also called as reserved words.

Example

pass, break, continue.. etc are reserved for special meaning in Python. So, we should not declare keyword as a variable name.