Python Floor Division Operator

Floor Division Operator

Python Floor Division Operator takes two operands, one on the left and other on the right, and returns the floor (rounded to the lower ceiling point) of the quotient of the division operation.

The symbol used for Python Floor Division operator is //.

Syntax

Following is the syntax of Floor Division Operator in Python.

result = operand_1 // operand_2

where operand_1 and operand_2 are numbers and the result is the floor of the quotient when operand_1 is divided by operand_2.

Example 1: Floor Division of Integers

In this example, we shall take two integers, divide them, find the integer quotient that is rounded to the lower ceiling integer, and print the result.

Python Program

a = 14
b = 5

result = a // b
print('Quotient :', result)
Run Code Copy

Output

Quotient : 2

Now, let us take negative numbers and find the floor of the quotient when we do division with these negative numbers.

Python Program

a = -11
b = 5

result = a // b
print('Quotient :', result)
Run Code Copy

Output

Quotient : -3

-11/5 is -2.2. Floor of -2.2 is -3.

Example 2: Floor Division of Floating Point Numbers

We can compute the floor division of floating point numbers. In the following example, we initialize two floating point numbers, and find the floor of the quotient resulting from the division of these two numbers.

Python Program

a = 14.8
b = 5.1

result = a // b
print('Quotient :', result)
Run Code Copy

Output

Quotient : 2.0

Summary

In this tutorial of Python Examples, we learned what Python Floor Division Operator is, how to use it to find the floor of the quotient in the division of given two numbers.

Related Tutorials

Code copied to clipboard successfully 👍