Abuzar Shaiban
Abuzar Shaiban
In
Python
What is a Variable in Python?
A Python variable is the name given to a
memory location in a program . In simple
words, we can say that a variable is a
container that contains some information, and
whenever we need that information, we use
the name of that container to access it. Let's
create a variable:
a = 34 # Variable storing an integer
b = 23.2 # Variable storing real number
Here a and b are variables, and we can use a to access 34
and b to access 23.2. We can also overwrite the values in a
and b
Variable Naming Rules in Python
Variable name should start with letter(a to z, A To Z)
or underscore (_).
Valid : age , _age , Age
Invalid : 1age, age-,
a=100
print (a)
My_age=25
print (My_age)
Num_1=25
print (Num_1)
Re-declare a Variable
You can re-declare the variable even
after you have declared it once.
a=100
print(a)
a=‘AECS Jaduguda’
print(a)
Concatenate Variables
a='AECS'
b=1
print(a+b)
will throw error , as we cannot concatenate two
different datatypes. But
a='AECS'
b=1
print(a+str(b))
Result: AECS1
Delete a variable
You can also delete variable using the
command del "variable name".
a=100
del a
Print(a)