Python variables and data
types
INTRODUCTION OF PYTHON VARIABLES…
• VARIABLE IS A NAME THAT IS USED TO REFER TO THE
MEMORY LOCATION
• PYTHON VARIABLE IS ALSO KNOWN AS IDENTIFIER TO USED
TO HOLD THE VALUE
• PYTHON VARIABLE NAMES CAN BE GROUP OF BOTH OF
LETTER AND DIGITS
• USE LOWER CASE LETTER AND UPPER CASE LETTER ARE
DIFFERENT LIKE RAHUL AND RAHUL
• THEY USE THE UNDERSCORE THE VARIABLE LIKE (_A) &
(A_)
Python variables
● Variable naming rules
● Declaring variables
● Multiple Assignment
● Deleting variables
● Python Variable Types
Variable naming rules
► The first character of variable must be an alphabet or underscore(_)
► All the character except the first character may be an alphabet of lower
case like(a-z),upper case like(A-Z) and they use the digits(0-9)
► Identifier name must not use any white space and special character
(!,@,#,%)
► Identifier name must not be similar any keyword
► Identifier name are case sensitive for example :- NAME and name are
the different name not a same variable
► Example of valid identifier name is :- _a,a123 etc
declaring variables
● Python does not bind us to declare a variable before using the
validation
● It allow to create a variable at the required time
● We don’t need to declare explicitly variable
● We assign any value to the variable that variable declared
● The equal (=) operator is used to assign the value of variable
● Example :- A=10
A is a variable name and (=) use the assign the value and 10 is a
value of A
Python variables
● Example of python variable:-
First Declare variable
Second add next variable
Finally print the variable values
A=10
B=10
C=A+B
Print(c)
Example of variable
Name=“sourav”
Age=23
Salary=21500
print(Name)
print(Age)
print(Salary)
Or
Print(Name,Age,Salary)
Multiple Assignment
● Python allows us to assign a value to multiple variable in a single statement
It is known as Multiple Assignment
● We can apply multiple assignment in two ways
● Either by assigning a single value to multiple variables or assigning a multiple value in
multiple variables
Assigning single value to multiple
variables
● Example:-
a=b=c=100
print(a)
print(b)
print(c)
User assign the multiple variable and assign the single value to multiple variable
Like a and b and c variables value is 100
And next step is print the all values
Assigning multiple values to
multiple variables
● Example:-
a,b,c=10,20,30
print(a)
print(b)
print(c)
User assign the multiple variable and assign the multiple value
And second step print the all values
Deleting variables
● We can delete the variable use del keyword
syntax:-
del<variable_name>
Example :-
x=5
print(x)
del x
print(x)
I print the variable x and assign the value and print the value after printing the value Delete
the variable x