Difference between ‘/’ and ‘//’ in Python Division

The below table shows the differences with proper examples

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


Difference between / vs. // operator in Python

In this article, we will see the difference between the / vs // operator in Python

Similar Reads

Python Division Operator

The division operator ‘/ ‘ performs standard division, which can result in a floating-point number. However, if both the dividend and divisor are integers, Python will perform integer division only if the result is an integer. Otherwise, it will produce a floating-point result....

Floor Division in Python

...

Difference between ‘/’ and ‘//’ in Python Division

The floor division operator // performs division and returns the largest integer that is less than or equal to the division result. It truncates (rounds down) the fractional part of the result, ensuring that the result is always an integer....