Open In App

Difference between / vs. // operator in Python

Last Updated : 18 Sep, 2025
Comments
Improve
Suggest changes
2 Likes
Like
Report

In Python, both / and // are used for division, but they behave quite differently. Let's dive into what they do and how they differ with simple examples.

/ Operator

This operator is used for true division. No matter what the inputs are, result is always a floating-point number. Even if division is exact, Python still returns the result as a float. This operator preserves fractional part of the result.

Example: Here we divide 10 by 3 using /. Since / does true division, it keeps the decimal part.

Python
res = 10 / 3
print(res)
print(type(res))

Output
3.3333333333333335
<class 'float'>

Explanation: Dividing 10 by 3 gives 3.333... and / operator preserves the fractional value. The datatype of res is float.

// Operator

This operator is used for floor division. Instead of keeping fractional part, it returns largest integer less than or equal to the result. In other words, it rounds down answer towards negative infinity.

Example: Here we divide 10 by 3 using //. Unlike /, this operator removes the fractional part.

Python
res = 10 // 3 
print(res)
print(type(res))

Output
3
<class 'int'>

Explanation: actual division result is 3.333..., but // truncates everything after decimal, giving 3. The datatype of res here is int.

Key Difference: Negative Numbers

The most noticeable difference between / and // appears when negative numbers are involved.

Example: Here we divide -17 by 5 using both / and //.

Python
print(-17 / 5)  
print(-17 // 5) 

Output
-3.4
-4

Explanation:

  • / gives the exact decimal value (-3.4).
  • // rounds down towards negative infinity, so instead of -3, it becomes -4.

Comparison between / and //

To sum up everything we discussed above, here is the difference in tabular form:

FeatureDivision /Floor Division //
Return TypeAlways returns float (even if the result is a whole number)Returns int if both operands are integers, otherwise float
Fractional PartKeeps the fractional/decimal partRemoves the fractional part (rounds down)
Positive Example7 / 2 = 3.5
15 / 4 = 3.75
7 // 2 = 3
15 // 4 = 3
Negative Example-9 / 2 = -4.5
-22 / 4 = -5.5
-9 // 2 = -5
-22 // 4 = -6

Related articles: Python, Python Operators.


Article Tags :

Explore