Variables
Variables
Variables
A Variable is a storage location paired with an associated symbolic name.It contains some known or unknown quantity of information referred to as a value. It is basically a container for a particular
type of data.
In [1]:
# This is an Example of a Variable
Sum = "Addition";
Types of Values
Intiger
A number that doesn't contain decimal values
In [2]:
#This is an example of a variable containing an intiger
t = 4;
print(t)
print(type(t));
<class 'int'>
Float
In [ ]:
A number that which contains decimal values.
In [3]:
#This is an example of a variable containing float
y = 12.5;
print(y)
print(type(y))
12.5
<class 'float'>
String
A value containing letters and or characters
In [4]:
#This is an example of a variable containing string
p = "Hello World";
print(p)
print(type(p))
Hello World
<class 'str'>
Bool
A Bool is a True or False Value
In [5]:
#This is an example of a variable containing bool
e = True;
print(e)
print(type(e))
True
<class 'bool'>
Naming Rules
A variable must start with a letter or an underscore.
Only Letters, numbers and underscores can be used.
In [6]:
#Examples of valid variables
print(x)
print(type(x));
print(y)
print(type(y));
print(z)
print(type(z));
Hello World
<class 'str'>
False
<class 'bool'>
2021
<class 'int'>
print(p)
print(type(p));
print(q)
print(type(q));
print(r)
print(type(r));
Hello World
<class 'str'>
Hello World
<class 'str'>
Hello World
<class 'str'>
print(c)
print(type(c));
c = 1994;
print(c)
print(type(c));
Hello World
<class 'str'>
1994
<class 'int'>
Deleting a Variable
Deleting Variables can immensely increase the processing speed.
In [11]:
b = "Hello World";
print(b);
print(type(b));
del (b);
print(b)
print(type(b))
Hello World
<class 'str'>
---------------------------------------------------------------------------
<ipython-input-11-5b687506b312> in <module>
6 del (b);
----> 8 print(b)
9 print(type(b))