Integers are used for different mathematical operations where division is one of them. Integers can be divided by using the
/ operator which is the division operator used in Python. In this tutorial we examine the integer division operations like division of integers, converting the result to integer and division of integer with other number types like floating point.
Integer to Integer Division
Integer can be divided into an integer by using the division operator. The result type can change according to the situation but the result is stored as a floating-point number. In the following example, we can see that the results are stored as a floating-point number.
a = 9/3 print(a) b = 3/9 print(b)
Integer to Floating Point Division
Another case is the division of integer values into floating-point. The result can be integer or floating-point according to the situation.
a = 9/3.0 print(a) b = 3/9.0 print(b)
Floating Point to Integer Division
The floating-point numbers can be divided into the integers like below.
a = 9.0/3 print(a) b = 3.0/9 print(b)
Converting Division Result To Integer
As the division operation results are stored as floating-point numbers in some cases we may need to get an integer result. The
int() butilin method can be used to convert floating-point division results as an integer.
a = 9/3 print(int(a)) b = 3/9 print(int(b))