Last modified: Apr 06, 2026 By Alexander Williams
Python // vs /: Floor Division vs True Division
Python has two main division operators. They are / and //. They do different things. This can confuse beginners. This article explains both. You will learn when to use each one.
We will cover their behavior with integers and floats. We will also look at examples. You will see the output for each case. This will make the concept clear.
What is the / True Division Operator?
The / operator performs true division. It always returns a floating-point number. This happens even if the numbers divide evenly.
Think of it like a calculator. It gives you the precise quotient. The result is a float data type.
# Examples of True Division with /
print(10 / 2) # Even division
print(7 / 2) # Uneven division
print(5.0 / 2) # Float and integer
Output:
5.0
3.5
2.5
Notice all results are floats. The first result is 5.0, not 5. This is a key point. The / operator promotes the result to a float.
What is the // Floor Division Operator?
The // operator performs floor division. It returns the quotient rounded down to the nearest whole integer. It truncates the decimal part.
It does not round. It always goes toward the lower integer. This is called "flooring." The result's type depends on the inputs.
# Examples of Floor Division with //
print(10 // 2) # Even division
print(7 // 2) # 7/2 is 3.5, floor is 3
print(-7 // 2) # -7/2 is -3.5, floor is -4
print(5.0 // 2) # Result is float 2.0
Output:
5
3
-4
2.0
With two integers, result is an int. If a float is involved, result is a float. Note how -7 // 2 gives -4. It goes down on the number line.
Key Differences Summarized
Let's compare them side by side.
Result Type:/ gives a float. // gives an int or float based on inputs.
Operation:/ is precise division. // is division then floor.
Use Case: Use / for exact math. Use // when you need whole items, like splitting groups. It is common in algorithm problems.
Practical Examples and Common Uses
Seeing them in context helps. Here are real scenarios.
Example 1: Calculating Average
Use true division for an accurate average.
scores = [85, 92, 78, 90]
total = sum(scores)
average = total / len(scores) # Correct: Use /
print(f"Average score: {average}")
Output:
Average score: 86.25
Using // here would give 86.0, losing precision.
Example 2: Splitting Items into Groups
Use floor division to find complete groups.
total_students = 47
students_per_bus = 5
full_buses = total_students // students_per_bus # How many full buses?
leftover = total_students % students_per_bus # Students left over
print(f"Full buses: {full_buses}, Students left: {leftover}")
Output:
Full buses: 9, Students left: 2
Floor division tells us we can fill 9 buses completely. The %modulo operator finds the remainder.
Example 3: Converting Units
Use both operators together for clarity.
total_inches = 68
feet = total_inches // 12 # Floor division for whole feet
inches = total_inches % 12 # Remainder inches
print(f"{total_inches} inches is {feet} feet and {inches} inches.")
Output:
68 inches is 5 feet and 8 inches.
Important Behavior with Negative Numbers
This is a critical point. Floor division with negatives can be surprising.
The // operator floors toward negative infinity. It does not truncate toward zero. This is different from some other languages.
print( 7 // 2) # 3.5 -> floor is 3
print(-7 // 2) # -3.5 -> floor is -4 (goes down!)
print( 7 / 2) # 3.5
print(-7 / 2) # -3.5
Output:
3
-4
3.5
-3.5
Remember this rule. For //, always round down on the number line. This ensures (a // b) * b + (a % b) == a always holds true in Python.
Python 2 vs Python 3: A Historical Note
In Python 2, the / operator behaved differently. With two integers, it acted like floor division //. This caused much confusion.
Python 3 made a clear split. / is always true division. // is always floor division. This is a major improvement. If you are learning, you are likely using Python 3. This is the standard now.
Understanding data types in Python helps grasp why this change was made.
Conclusion
You now know the difference between / and // in Python.
Use the single slash / for true division when you need a precise, floating-point result. Use the double slash // for floor division when you need an integer quotient, like counting complete groups.
Remember the behavior with negative numbers for //. Practice with the examples. This will solidify your understanding. Choosing the right operator makes your code clearer and more correct.