Numeric data types are numbers stored in the memory. You can perform operations such as addition, subtraction, multiplication, division, modulo, etc on numeric data. The following data types can be categorized as numeric types.
int
float
complex
Integer type
Integers are the whole numbers means there are no floating-point values in them. A variable of integer type is created when you assign an integer value to the variable. In Python, integers can be of any length, it is only constrained by the amount of memory your system has.
Examples of integers
0, 2, -5, 100, 852200
Examples of non-integers
0.2, 8.1, 2*5.1, 2j
Float type
These numbers are specified by a decimal point. A variable of the float type is created when you assign a float value to the variable. A number that is expressed with e
or E
character is also float type.
Usually, all the platforms represent float values with 64-bit double-precision values. The maximum value that a float variable can have is approximately 1.8e308
, a value greater than this is represented by the string inf
in Python.
You can see this in the image below –
Examples of float type
5.4, 0.2, 2/3, -0.000111, 12e8, 3E34
Complex type
Complex numbers are written in the form of a+bj
where a
is real part and bj
is the imaginary part.
Examples of complex type
2+3j, 5j, -2.7j
Example of Python numeric type of data
A variable of type int, float, or complex is created when you assign a numeric value to it. Now see the given example that shows the usage of different data types i.e. int, float, and complex in Python.
x=2 # x contains integer value y=3.5 # y contains float value z=-3.1j # z contains complex number print(type(x)) print(type(y)) print(type(z))
Since data types are classes and the variables are instances of those classes in Python now the output will display the class name that you can see in the image below –
Next, we will learn the boolean data type in Python along with some examples.