2. VARIABLES
Variables are nothing but used to store the data. It is part of the computer’s memory. Each variable is assigned a
name that can be used to refer to the values.
ASSIGNING A VALUE TO VARIABLES:
The value will be assigned to variables by using the = sign.
For Example:
a=3
a is the variable name
= is the assignment operator
3 is value. so value 3 is assigned to variable a.
3. REASSIGN A VALUE TO VARIABLES:
In Python, Values can be reassigned to variables as many times
as Python has no specific datatype.
You can assign an integer value to variables and later on, you
can assign the float/string variable to the same variable.
For example
.
.
>>> a='hello’ #string
>>> print(a)
hello
>>> a= 5 #integer
>>> print(a)
5
>>> a=5.0 #float
>>> print(a)
5.0
4. Assigning Multiple values to Multiple
variables
We can assign multiple values to multiple variables at once.
For example:
a, b, c =3,7,’hello’
print(a)
print (b)
Print(c)
5. Rules for Naming Python
Variables
Constant and variable names should have a combination of
letters in lowercase (a to z) or uppercase (A to Z) or digits (0 to
9) or an underscore (_).
If you want to create a variable name having two words, use
underscore to separate them.
e.g
first_name
Emp_salary
Python is case-sensitive. So num and Num are different
variables.
We should avoid using keywords such as if, True, class, etc.
as varibles names.