Floor division in Python is performed using the // operator, which divides two numbers and returns the largest integer less than or equal to the result, effectively rounding down to the nearest whole number.

  • Syntax: a // b

  • Behavior:

    • For positive numbers, it behaves like truncating the decimal part (e.g., 7 // 2 = 3).

    • For negative numbers, it rounds toward negative infinity (e.g., -7 // 2 = -4, not -3).

  • Result type:

    • If both operands are integers, the result is an integer.

    • If at least one operand is a float, the result is a float (e.g., 7.5 // 2 = 3.0).

Key differences from standard division (/):

  • / always returns a float (e.g., 7 / 2 = 3.5).

  • // returns an integer or float depending on input types, but always rounds down.

Common use cases:

  • Calculating indices (e.g., mid = (left + right) // 2 in binary search).

  • Pagination: total_pages = (total_items + items_per_page - 1) // items_per_page.

  • Splitting data into chunks: num_chunks = len(data) // chunk_size.

Alternative method: Use math.floor(x / y) to achieve the same result, though // is more efficient and idiomatic.

💡 Note: The // operator is also known as integer division in Python, but it differs from other languages (like JavaScript) in how it handles negative numbers.

In Python 3.x, 5 / 2 will return 2.5 and 5 // 2 will return 2. The former is floating point division, and the latter is floor division, sometimes also called integer division.

In Python 2.2 or later in the 2.x line, there is no difference for integers unless you perform a from __future__ import division, which causes Python 2.x to adopt the 3.x behavior.

Regardless of the future import, 5.0 // 2 will return 2.0 since that's the floor division result of the operation.

You can find a detailed description at PEP 238: Changing the Division Operator.

Answer from Eli Courtwright on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › floor-division-in-python
Floor Division in Python - GeeksforGeeks
July 23, 2025 - Floor division is a division operation that returns the largest integer that is less than or equal to the result of the division. In Python, it is denoted by the double forward slash '//'.
🌐
LearnDataSci
learndatasci.com › solutions › python-double-slash-operator-floor-division
Python Double Slash (//) Operator: Floor Division – LearnDataSci
In Python, we can perform floor division (also sometimes known as integer division) using the // operator.
People also ask

What Does Floor Mean in Python?
In Pythonfloor’ refers to rounding a number down to the nearest integer, disregarding the fractional part. This can be done using the math.floor() function or using the ‘//’ operator. For instance, math.floor (4.7) or 4.7 // 1 would return 4. It is important in all calculations requiring integer values.
🌐
theknowledgeacademy.com
theknowledgeacademy.com › blog › floor-division-in-python
Floor Division in Python: Everything You Need to Know
Why Would You Use Floor Division?
Floor Division is used when only the whole number portion of a division is required, ignoring the remainder. Examples include evenly dividing items (e.g., oranges), calculating integer averages, or converting seconds to minutes.
🌐
theknowledgeacademy.com
theknowledgeacademy.com › blog › floor-division-in-python
Floor Division in Python: Everything You Need to Know
What are the Related Courses and Blogs Provided by The Knowledge Academy?
The Knowledge Academy offers various Programming Training, including the Python Course, PHP Course and the Vue.js Framework Training. These courses cater to different skill levels, providing comprehensive insights into Python Enumerate. Our Programming and DevOps cover a range of topics related to Python, offering valuable resources, best practices, and industry insights. Whether you are a beginner or looking to advance your Programming Skills, The Knowledge Academy's diverse courses and informative blogs have got you covered.
🌐
theknowledgeacademy.com
theknowledgeacademy.com › blog › floor-division-in-python
Floor Division in Python: Everything You Need to Know
🌐
Mimo
mimo.org › glossary › python › floor-division
Python Floor Division: Syntax, Usage, and Examples
Understanding the difference between the standard division (/) and the Python double slash operator is essential. Here's a comparison: ... The standard division always returns a float, while floor division truncates the decimal part.
🌐
The Knowledge Academy
theknowledgeacademy.com › blog › floor-division-in-python
Floor Division in Python: Everything You Need to Know
February 5, 2026 - Wondering how Floor Division in Python works? It’s a mathematical operation that divides two numbers and rounds down to the nearest whole number. This blog explains the concept with examples, covering its syntax, use cases, and tips to use it effectively in Python programming.
Find elsewhere
🌐
W3Schools
w3schools.com › python › python_operators_arithmetic.asp
Python Arithmetic Operators
Python has two division operators: / - Division (returns a float) // - Floor division (returns an integer) Division always returns a float: x = 12 y = 5 print(x / y) Try it Yourself » · Floor division always returns an integer.
🌐
Quora
quora.com › What-does-floor-division-in-Python-do
What does floor division ('//') in Python do? - Quora
Python (programming langu... ... Computer Science and Prog... ... Floor division in Python (operator //) divides two numbers and returns the mathematical floor of the quotient — the largest integer less than or equal to the true quotient.
🌐
YouTube
youtube.com › watch
Python Under 5 Minutes: Floor Division - YouTube
In this video, we will go over floor division in Python. We will look at how division is handled in Python and how we can handle just getting a whole number...
Published   September 8, 2023
Top answer
1 of 3
29

Use this. this will help you.

a,b = divmod(10,2)

it will return both value

2 of 3
12

There is a significant difference in performance if you use larger numbers.

Here is an example using both small and large numbers:

$ py27 -m timeit -s "a=123;b=7" "divmod(a,b)"
10000000 loops, best of 3: 0.0913 usec per loop
$ py27 -m timeit -s "a=123;b=7" "a//b;a%b"
10000000 loops, best of 3: 0.047 usec per loop
$ py27 -m timeit -s "a=123333333333333333333333333333333333333;b=7222222222222222222" "divmod(a,b)"
10000000 loops, best of 3: 0.165 usec per loop
$ py27 -m timeit -s "a=123333333333333333333333333333333333333;b=7222222222222222222" "a//b;a%b"
1000000 loops, best of 3: 0.232 usec per loop

Why the difference?

divmod() requires a function call while // and % are operators. There is additional overhead for a function call relative to operators. So when the cost of the computation is minimal, the overhead of calling a function is much greater than the actual cost of the calculation(s).

For larger numbers, divmod() is faster. divmod() calculates both the quotient and remainder at the same time and returns both of them. The // and % operators each calculate the quotient and remainder but only return one of the results.

divmod() has more overhead but only performs one division. // and % have less overhead but perform two divisions. As long as the overhead is large compared to time to perform division, divmod() will be slower. But once the cost of a division is greater than the overhead, divmod() will be faster.

🌐
Python.org
discuss.python.org › python help
Integer division - Python Help - Discussions on Python.org
January 25, 2023 - What is the result of this code: print(6 // 0.4) I thought the answer is 15.0 but I am getting 14.0. Any explanation for this answer I will appreciate.
🌐
NxtWave
ccbp.in › blog › articles › floor-division-in-python
Floor Division in Python: Explained with Examples
April 30, 2025 - Floor Division in Python is a mathematical operation in Python that divides two numbers and rounds the result down to the nearest whole number (integer or float, depending on the operands).
🌐
OpenStax
openstax.org › books › introduction-python-programming › pages › 2-5-dividing-integers
2.5 Dividing integers - Introduction to Python Programming | OpenStax
March 13, 2024 - Ex: 7 / 4 becomes 7.0 / 4.0, resulting in 1.75. Floor division (//) computes the quotient, or the number of times divided. Ex: 7 // 4 is 1 because 4 goes into 7 one time, remainder 3. The modulo operator (%) computes the remainder.
🌐
The Teclado Blog
blog.teclado.com › pythons-modulo-operator-and-floor-division
Python's modulo operator and floor division
October 26, 2022 - The amount left over after the ... to carry out Euclidean division, but unlike the modulo operator, floor division yields the quotient, not the remainder....
🌐
Metaschool
metaschool.so › home › answers › what is floor division in python? guide with examples
What is Floor Division in Python? Guide With Examples
December 6, 2024 - In Python, floor division is a powerful operator that allows you to divide two numbers and return the largest integer less than or equal to the result. Unlike regular division, which can produce a floating-point number, floor division simplifies ...
🌐
Python
peps.python.org › pep-0238
PEP 238 – Changing the Division Operator | peps.python.org
We propose to fix this by introducing different operators for different operations: x/y to return a reasonable approximation of the mathematical result of the division (“true division”), x//y to return the floor (“floor division”).