A variable is a location in memory used to store some data (value).
They are given unique names to differentiate between different memory locations. The rules for writing a variable name is same as the rules for writing identifiers in Python.
We don't need to declare a variable before using it. In Python, we simply assign a value to a variable and it will exist. We don't even have to declare the type of the variable. This is handled internally according to the type of value we assign to the variable
We use the assignment operator (=) to assign values to a variable. Any type of value can be assigned to any valid variable.
Assignment Example
a = 7
b = 3.14
c = "Hello World"
Click on the run button below to see the output of the python code assigning variables
See if you can improve the output of the code above?
Every value in Python has a datatype. Since everything is an object in Python programming, data types are actually classes and variables are instance (object) of these classes.
There are various data types in Python. Some of the important types are listed below.
Integers, floating point numbers and complex numbers falls under Python numbers category. They are defined as int, float and complex class in Python.
We can use the type() function to know which class a variable or a value belongs to.
Type Example
a = 7
print(a, "is of type", type(a))
b = 3.14
print(b, "is of type", type(b))
c = "Hello World"
print(c, "is of type", type(c))
Recent Comments
Teacher Date: 2025-09-28
Guest