Python Division

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.

// 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 // operator.

Python Program

a, b = 7, 3
result = a//b
print(result)
Run this program

Output

2

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.

Python Program

a, b = 7.2, 3.1
result = a//b
print(result)
Run this program

Output

2.0

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 / operator.

Division operator / 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 / operator.

Python Program

a, b = 7, 3
result = a/b
print(result)
Run this program

Output

2.3333333333333335

For float division, you can give any number for arguments of types: int or float.

Summary

In this tutorial of Python Examples, we learned how to perform two types of Python Division namely: Integer Division and Float Division.