Python Division – Integer Division & Float Division
Division operation is an arithmetic operation where we shall try to compute how much we have to divide dividend into equal parts, so that each of the divisor will get an equal amount.
In Python programming, you can perform division in two ways. The first one is Integer Division and the second is Float Division.
In this tutorial, we will learn how to perform integer division and float division operations with example Python programs.
Python Integer Division
Integer division means, the output of the division will be an integer. The decimal part is ignored. In other words, you would get only the quotient part. To perform integer division in Python, you can use
// operator accepts two arguments and performs integer division. A simple example would be
result = a//b.
In the following example program, we shall take two variables and perform integer division using
a, b = 7, 3 result = a//b print(result)
You can also provide floating point values as operands for
// operator. In the following example, we shall take two float values and compute integer division.
a, b = 7.2, 3.1 result = a//b print(result)
The result is a float, but only quotient is considered and the decimal part or reminder is ignored.
Python Float Division
Float division means, the division operation happens until the capacity of a float number. That is to say result contains decimal part. To perform float division in Python, you can use
/ accepts two arguments and performs float division. A simple example would be
result = a/b.
In the following example program, we shall take two variables and perform float division using
a, b = 7, 3 result = a/b print(result)
For float division, you can give any number for arguments of types: int or float.
In this tutorial of Python Examples, we learned how to perform two types of Python Division namely: Integer Division and Float Division.