When I build Python automation scripts for monthly sales reports, invoice checks, or file-processing jobs, division comes up more often than people expect. You may need to calculate an average order value, split a batch into equal groups, or work out how many full boxes you can ship.
That is where the difference between Python / and // matters. They both divide numbers, but they return different types of results and solve different problems. If you need a refresher on Python numeric values, see this guide on floating-point numbers in Python and this explanation of how to convert a float to an integer in Python.
This practical Python tutorial shows exactly when to use each operator, how negative numbers behave, and how to avoid common calculation mistakes.
Python / vs // at a Glance
Python provides two main division operators:
| Operator | Name | What it returns | Example |
|---|---|---|---|
/ | True division | A decimal number (float) | 7 / 2 returns 3.5 |
// | Floor division | The result rounded down to the next whole number | 7 // 2 returns 3 |
The primary difference is simple:
- Use
/when you need the precise result, including decimal places. - Use
//when you only need the number of complete groups, pages, rows, or batches.
For example, if Emily runs a small shipping report in Austin and divides 25 orders across 6 delivery drivers:
25 / 6gives4.166666666666667orders per driver.25 // 6gives4complete orders per driver group.
The first result helps with averages. The second helps when the script must count complete units. When you also need to calculate the leftover items, use the % operator; this guide explains what the percent sign means in Python.
What Does / Do in Python?
The / operator performs true division. It returns a float, which is a number that can include decimal places.
Python 3 uses true division by default, even when you divide two integers. You can also learn more about the key language differences in this Python 3 vs Python 2 comparison.
Basic Python / Example
total_sales = 1250
number_of_days = 7
average_sales = total_sales / number_of_days
print(average_sales)
Output:
178.57142857142858
I executed the above example code and added the screenshot below.

Here, total_sales and number_of_days are both integers. Still, Python returns a float because / preserves the fractional part of the answer.
This is useful in a reporting script where you need an accurate daily average rather than a rounded number.
Python / With Integers
print(10 / 2)
print(9 / 2)
print(1 / 4)
Output:
5.0
4.5
0.25
Notice that 10 / 2 returns 5.0, not 5. Python returns a float every time you use /. To understand this result type better, see this guide on floating-point numbers in Python.
That behavior makes calculations predictable. You do not need to check whether a division produces a whole number before deciding what type Python will return. If you later need to change the result into a whole number, learn how to convert a float to an integer in Python.
What Does // Do in Python?
The // operator performs floor division. It divides two values and rounds the answer down to the nearest whole number. For a deeper explanation of rounding down, see how to use the floor function in Python and floor a number in Python.
The word “floor” means the lower whole number. Python moves down on the number line, not simply toward zero. This differs from standard rounding, which you can explore in this guide on the round function in Python.
Basic Python // Example
total_files = 25
files_per_batch = 6
complete_batches = total_files // files_per_batch
print(complete_batches)
Output:
4
I ran the example code above and added the screenshot below.

The result is 4 because four complete batches contain 24 files. One file remains.
This is useful when writing a local automation script that processes records in fixed-size batches. If your API allows 100 records per request, // helps you calculate full request batches.
Python // With Floats
print(15 // 4)
print(15.0 // 4)
print(15 // 4.0)
Output:
3
3.0
3.0
When both values are integers, Python returns an integer. If either number is a float, Python returns a float. If you need to confirm a value before using it, learn how to check whether a string is an integer or float in Python.
That small detail matters when you later format output, store results in a database, or use values inside a list index.
Python / vs // With a Real Example
Let’s use a practical example: a Python script that prepares a customer report for a fictional office supply company in Chicago.
The company has 157 printed invoices. The operations team wants to know:
- The average number of invoices each employee handles.
- The number of complete invoice bundles when each bundle holds 20 invoices.
- The number of invoices left after making full bundles.
total_invoices = 157
employees = 8
invoices_per_bundle = 20
average_per_employee = total_invoices / employees
complete_bundles = total_invoices // invoices_per_bundle
remaining_invoices = total_invoices % invoices_per_bundle
print("Average invoices per employee:", average_per_employee)
print("Complete bundles:", complete_bundles)
print("Invoices left over:", remaining_invoices)
Output:
Average invoices per employee: 19.625
Complete bundles: 7
Invoices left over: 17
I executed the above example code and added the screenshot below.

Here is why each operator fits:
/gives the exact average, including the partial invoice allocation.//gives only fully completed bundles.%, called the modulus operator, returns the remainder.
In real scripts, // and % often work together. One tells you how many complete groups exist, while the other tells you what remains. For a closer look at %, read what the percent sign means in Python.
Pro Tip: I have found that many calculation bugs happen because developers use
int(a / b)instead ofa // b. They look similar for positive numbers, but they behave differently when negative values enter the calculation.
Python / vs // With Negative Numbers
Negative values show the most important difference between /, //, and converting a result with int().
True Division With Negative Numbers
print(-7 / 2)
print(7 / -2)
Output:
-3.5
-3.5
The / operator keeps the decimal part, so the answer remains exact.
Floor Division With Negative Numbers
print(-7 // 2)
print(7 // -2)
Output:
-4
-4
Some beginners expect -7 // 2 to return -3. But Python returns -4 because floor division rounds down, toward negative infinity.
On a number line:
-3.5sits between-3and-4.- The floor of
-3.5is-4.
This behavior is correct, but you need to remember it when working with offsets, date calculations, balances, or coordinate values.
Why int() Is Not the Same as //
division_result = -7 / 2
print("Division result:", division_result)
print("Using int():", int(division_result))
print("Using //:", -7 // 2)
Output:
Division result: -3.5
Using int(): -3
Using //: -4
The int() function removes the decimal portion by moving toward zero. Floor division moves down to the lower integer.
Use int() only when you specifically want truncation toward zero. Use // when you need actual floor division; see this guide on the floor function in Python for a related explanation.
When Should You Use Python /?
Use Python / whenever the decimal part has meaning.
Calculate an Average
weekly_hours = 37
work_days = 5
average_hours = weekly_hours / work_days
print("Average hours per day:", average_hours)
Output:
textAverage hours per day: 7.4An average is usually not a whole number. Using // here would lose useful information.
Calculate a Percentage
completed_tasks = 43
total_tasks = 50
completion_percentage = (completed_tasks / total_tasks) * 100
print("Completion percentage:", completion_percentage)
Output:
Completion percentage: 86.0
A percentage calculation needs true division because you want the accurate ratio before multiplying by 100.
Calculate a Unit Price
total_cost = 89.95
number_of_items = 6
cost_per_item = total_cost / number_of_items
print("Cost per item:", cost_per_item)
Output:
Cost per item: 14.991666666666667
For money, you should normally format or round the final value.
total_cost = 89.95
number_of_items = 6
cost_per_item = total_cost / number_of_items
print(f"Cost per item: ${cost_per_item:.2f}")
Output:
Cost per item: $14.99
When Should You Use Python //?
Use Python // when the decimal portion does not represent a usable partial unit.
Split Records Into Full Batches
total_records = 1250
records_per_batch = 100
full_batches = total_records // records_per_batch
remaining_records = total_records % records_per_batch
print("Full batches:", full_batches)
print("Remaining records:", remaining_records)
Output:
Full batches: 12
Remaining records: 50
This pattern works well in automation scripts that send records to an API in fixed-size requests.
Calculate Complete Pages
total_products = 98
products_per_page = 12
full_pages = total_products // products_per_page
products_on_last_page = total_products % products_per_page
print("Full pages:", full_pages)
print("Products on the last page:", products_on_last_page)
Output:
Full pages: 8
Products on the last page: 2
A web application may show eight full pages of products and two products on a final page.
Convert Seconds Into Full Minutes
total_seconds = 367
full_minutes = total_seconds // 60
remaining_seconds = total_seconds % 60
print(f"{full_minutes} minutes and {remaining_seconds} seconds")
Output:
6 minutes and 7 seconds
This is a classic use case for floor division. You cannot show 6.116 minutes in a user-friendly timer, so you split the value into complete minutes and remaining seconds. If you are building a timer application, this guide on creating a Python Tkinter stopwatch is a useful next step.
Python Division Operator Types
Python supports several numeric types, and division results can change depending on the values you provide.
Integer Division
print(20 / 5)
print(20 // 5)
Output:
4.0
4
The mathematical result is the same, but the data type differs:
/returns4.0, a float.//returns4, an integer.
Float Division
print(20.0 / 5)
print(20.0 // 5)
Output:
4.0
4.0
Because one number is a float, both results are floats.
Check the Result Type
true_division = 20 / 5
floor_division = 20 // 5
print(type(true_division))
print(type(floor_division))
Output:
<class 'float'>
<class 'int'>
Checking types helps when you pass calculated values into another function. For example, functions such as range() require integer values.
total_items = 25
items_per_group = 5
groups = total_items // items_per_group
for group_number in range(groups):
print("Processing group", group_number + 1)
Output:
Processing group 1
Processing group 2
Processing group 3
Processing group 4
Processing group 5
Avoid Division by Zero Errors
Both / and // raise a ZeroDivisionError if you divide by zero. An exception is an error that interrupts normal program execution.
total_orders = 120
number_of_drivers = 0
result = total_orders / number_of_drivers
print(result)
Output:
ZeroDivisionError: division by zero
In a real script, validate the divisor before calculating.
total_orders = 120
number_of_drivers = 0
if number_of_drivers != 0:
average_orders = total_orders / number_of_drivers
print("Average orders:", average_orders)
else:
print("Cannot calculate average because the driver count is zero.")
Output:
Cannot calculate average because the driver count is zero.
This simple check makes your script safer when values come from a CSV file, form, API, or user input.
Things to Keep in Mind
- Use
/for precision: Choose true division when averages, percentages, measurements, rates, or prices need decimal values. - Use
//for complete units: Choose floor division for batches, pages, groups, boxes, and time conversions where partial units do not count. - Remember negative values: Python
//rounds down, not toward zero, so-7 // 2returns-4. - Check for zero divisors: Validate any number that comes from user input, files, or external data before division.
- Use
%with//: The modulus operator shows the remainder after you calculate complete groups. - Round display values carefully: Use formatting such as
:.2ffor output, especially when displaying prices or percentages.
Frequently Asked Questions
What is the difference between / and // in Python?
/ performs true division and returns a float with decimal places when needed. // performs floor division and returns the result rounded down to the nearest whole number.
Why does Python / return 5.0 instead of 5?
Python 3 always returns a float when you use the / operator. This creates consistent behavior, even when the division result has no decimal portion.
Does // always return an integer in Python?
No. It returns an integer when both operands are integers. If either operand is a float, Python returns a float, such as 10.0 // 3, which returns 3.0.
What does -7 // 2 return in Python?
It returns -4. Floor division rounds down toward negative infinity, so Python moves from -3.5 to -4.
Can I use int(a / b) instead of a // b?
You can for many positive values, but they are not equivalent for negative values. int(-7 / 2) returns -3, while -7 // 2 returns -4.
How do I get the remainder after floor division?
Use the % modulus operator. For example, 25 // 6 returns 4, while 25 % 6 returns 1.
Python / gives you accurate decimal results, while // gives you complete groups by rounding down. Start with / for averages and measurements, then use // with % when your script handles batches, pages, timers, or other whole-unit tasks.
You May Also Like
- Call a Function in Python
- Define a Function in Python
- Get the Name of a Function in Python
- Use the Input() Function in Python

Bijay Kumar is an experienced Python and AI professional who enjoys helping developers learn modern technologies through practical tutorials and examples. His expertise includes Python development, Machine Learning, Artificial Intelligence, automation, and data analysis using libraries like Pandas, NumPy, TensorFlow, Matplotlib, SciPy, and Scikit-Learn. At PythonGuides.com, he shares in-depth guides designed for both beginners and experienced developers. More about us.