Difference between / vs. // operator in Python
Last Updated :
28 Apr, 2025
Improve
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 (True Division)
- The / operator performs true division.
- It always returns a floating-point number (even if the result is a whole number).
- It keeps the decimal (fractional) part.
Example:
res = 10 / 3
print(res)
print(type(res))
Output
3.3333333333333335 <class 'float'>
Explanation:
- Dividing 10 by 3 gives 3.333..., and / keeps the fractional part
- Data-type of res is float.
// Operator (Floor Division)
- The // operator performs floor division.
- It returns the largest integer less than or equal to the division result.
- It truncates (removes) the decimal part and rounds down towards negative infinity.
Example:
res = 10 // 3
print(res)
print(type(res))
Output
3 <class 'int'>
Explanation:
- The actual division result is 3.333..., but // drops everything after the decimal, giving 3.
- Data-type of res here is int.
Comparison between '/' and '//'
Feature | Division Operator (/) | Floor Divsion Operator (//) |
---|---|---|
Return Type | Floating-point. Returns in integer only if the result is an integer | Integer |
Fractional Part | Returns the fractional part | Truncates the fractional part |
Examples |
|
|
Related articles: Python, Python Operators.