# Python Numbers – Int, Float | Type Conversion

There are three types of numeric data in python.

1. int
2. float
3. complex

For example:

``````x = 1
y = 2.5
z = 3j

print(type(x))
print(type(y))
print(type(z))``````

Output:

``````<class 'int'>
<class 'float'>
<class 'complex'>``````

## Integer

Let’s start off with integer, an integer is well a whole number like 2, 3 or 4, positive or negative without decimal.

You can use integers to do mathematical operations for example 2 + 4.

``````x = 5
y = -2

z = x + y

print(z)``````

Output:

``3``

## Float

Floating point number or float is a decimal number which is positive or negative.

``````x = 5.5
y = 7

z = x + y

print(z)
print(type(z))``````

Output:

``````12.5
<class 'float'>``````

We also an ‘e’ in float number which indicates the power of 10.

``````x = 12E4
y = 12.e4

print(type(x))
print(type(y))``````

Output:

``````<class 'float'>
<class 'float'>``````

## Complex

Complex number is an imaginary number which is written with a ‘j’.

``````x = 4j
y = 5j

z = x + y

print(z)
print(type(z))``````

Output:

``````9j
<class 'complex'``````

## Number Type Conversion

Convert a data type to another type by using int(), float(), complex(), and str() method to satisfy the requirements of an operator or function parameter.

``````x = 10    # int
y = 3.5  # float

#convert from int to float:
a = float(x)

#convert from float to int:
b = int(y)

#convert from int to complex:
c = complex(x)

print(a)
print(b)
print(c)

print(type(a))
print(type(b))
print(type(c))``````

Output:

``````10.0
3
(10+0j)
<class 'float'>
<class 'int'>
<class 'complex'>``````

## Some Mathematical Functions

Python has the following mathematical functions to performs calculations:

Scroll to Top