Open In App

Difference between / vs. // operator in Python

Last Updated : 28 Apr, 2025
Comments
Improve
Suggest changes
Like Article
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 (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:

Python
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:

Python
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

  • 10 / 3 = 3.333333...
  • 10 / 5 = 2.0
  • 5 / 2 = 2.5
  • -17 / 5 = -3.4
  • -17 / -5 = 3.4
  • 10 // 3 = 3
  • 10 // 5 = 2
  • 5 // 2 = 2
  • -17 // 5 = -4
  • -17 // -5 = 3

Related articles: Python, Python Operators.


Next Article
Article Tags :
Practice Tags :

Similar Reads