What Does // Mean in Python?
Short answer: In Python, the double slash // is the floor division operator: it divides and rounds the result down to the nearest whole number. For example, 19 // 5 returns 3, while 19 / 5 returns 3.8. With negative numbers it still rounds down (-19 // 5 is -4), and with floats it returns a float (10 // 2.5 is 4.0).
One of the many operators in Python is the double slash // operator, which refers to an integer division (or a division with no remainder/decimals) which is called Floor Division. When dividing two integers using this // operator, the result will always be an integer, rounded down to the nearest whole number.
num1 = 19
num2 = 5
result1 = num1 / num2
result2 = num1 // num2
print("normal division of", num1, "by", num2, "=", result1)
print("floor division of", num1, "by", num2, "=", result2)
# Output:
# normal division of 19 by 5 = 3.8
# floor division of 19 by 5 = 3The double slash // has the same function as the Python method math.floor (which we will discuss later), as its name implies, rounds the result down (rounds to its floor) to the closest integer.

In this article, we will review more thoroughly how the Floor Division differs from a normal division, how the // operator works with different types of numbers (negative numbers and decimal numbers) and some extra methods similar to a Floor Division.
Difference Between Floor Division // and Regular Division /
A normal division / in Python will always return a number with its decimal part, that is, a floating number, while a floor division between two integers will always return an integer number (if a float is involved, it returns a float).
The result of regular division (using the / operator) is 45/6=7.5, but using // has floored 7.5 down to 7.
Working with Negative Numbers in Floor Divisions
To understand how to work with negative numbers using floor division, we need to understand that the floor of a positive number is different from the floor of a negative number. For example, the floor of 3.4 is 3, but the floor of -3.4 is -4, not -3. For greater understanding, we could say that the floor of any number is always the integer below it, so for a negative number it is the integer further from zero.
We can see another example as follows using the same numbers as before:
num1 = 19
num2 = 5
num3 = -19
result1 = num1 / num2
result2 = num1 // num2
result3 = num3 // num2
print("normal division of", num1, "by", num2, "=", result1)
print("floor division of", num1, "by", num2, "=", result2)
print("floor division of", num3, "by", num2, "=", result3)
# Output:
# normal division of 19 by 5 = 3.8
# floor division of 19 by 5 = 3
# floor division of -19 by 5 = -4Working with Floats in Floor Divisions
When we work with float numbers using floor division, the result will always be a float number, and as we already know, the result will be the nearest integer rounded to its floor, but in this case, it will be represented by a float number.
Let's have a look at the following float-based floor division example:
num1 = 17.5
num2 = 3.3
num3 = 10
num4 = 2.5
num5 = 13.4
num6 = 3
result1 = num1 // num2
result2 = num3 // num4
result3 = num5 // num6
print("floor division of", num1, "by", num2, "=", result1)
print("floor division of", num3, "by", num4, "=", result2)
print("floor division of", num5, "by", num6, "=", result3)
# Output:
# floor division of 17.5 by 3.3 = 5.0
# floor division of 10 by 2.5 = 4.0
# floor division of 13.4 by 3 = 4.0As a result, the floor division operation is carried out using floats, and a float with an integer returns the value rounded down to the nearest integer represented by the floats.
Similar Methods of a Floor Division
In Python, there are several methods similar to operations with // (floor division). But, how would these other methods be useful to us? It all depends on our use case, in some situations we will find ourselves needing to handle only integers in our projects, and since floor division operations can get both integers and floats, we could use a hand in these cases.
This is where these two additional methods come in, which are math.floor() and math.ceil, they will allow us to manipulate the result so that it is always an integer.
math.floor() Function in Python
Python comes with a built-in math module that includes a variety of practical calculating tools. The math.floor() function is one of the math module's built-in features. This function takes a numeric input and rounds it down to the closest integer to return the floor value.
Therefore, math.floor() is an alternative to the // operator since they accomplish the same goal in the background, but always returning an integer.
Let's have a look at the following example:
# importing the math library
import math
# using the math.floor() function and printing the values
print(math.floor(2.4)) #Output 2
print(math.floor(9.3)) #Output 9
print(math.floor(-7.3)) #Output -8
print(math.floor(25.7)) #Output 25
print(math.floor(11.0)) #Output 11math.ceil() Function in Python
math.ceil() is an alternative to math.floor() but it will always round up to the nearest whole number rather than down.
For instance:
# importing the math library
import math
# using the math.ceil() function and printing the values
print(math.ceil(2.4)) #Output 3
print(math.ceil(9.3)) #Output 10
print(math.ceil(-7.3)) #Output -7
print(math.ceil(25.7)) #Output 26
print(math.ceil(11.0)) #Output 11Summary
The next video will be of great help to better understand what was explained in this What Does // Mean in Python? article
Floor division with the // operator is one of many Python fundamentals that sink in faster when you use them in real projects. A coding bootcamp adds that structure, with guided projects and mentors who review your code.
Frequently asked questions
Does // always return an integer in Python?
No. The // operator returns an int only when both operands are integers. If either operand is a float, the result is a float with no fractional part, so 10 // 2.5 returns 4.0 and 17.5 // 3.3 returns 5.0. Wrap the expression in int() when the code needs an integer type, for example to use the result as a list index.
What is the difference between // and % in Python?
// returns the quotient of a division rounded down, while % returns the remainder. For example, 19 // 5 is 3 and 19 % 5 is 4, because 3 * 5 + 4 equals 19. Both operators always satisfy a == (a // b) * b + a % b. To get both values in one call, use divmod(19, 5), which returns the tuple (3, 4).
Is // the same as int(a / b) in Python?
Not always. Both give the same answer for positive results, but int() truncates toward zero while // rounds down toward negative infinity, so int(-19 / 5) returns -3 and -19 // 5 returns -4. Also, a / b produces a float first, which can lose precision with very large integers, whereas // between two integers stays exact.
What does //= do in Python?
//= is the augmented assignment form of floor division: x //= 3 is shorthand for x = x // 3. It divides the variable, rounds the result down and stores it back in the same variable. For instance, if x is 19, then x //= 5 leaves x equal to 3. It is common in loops that strip digits from a number, such as n //= 10.

