Difference Between / and // in Python with Examples

If you are new to Python, you might have come across the symbols “/“ and “//“ in mathematical operations, particularly in division.

The forward slash “/“ serves as a normal division, while the double forward slash “//“ serves as a floor division.

The “/“ Operator: Normal Division

The forward slash “/“ is the standard division operator in Python. When you use this operator, Python will perform a normal division, resulting in a floating-point number as the output.

Let’s consider an example:

Example:

5 / 2
 2.5

In this example, when we divide 5 by 2 using “/“, Python returns the result 2.5 as a floating-point number.

The “//“ Operator: Floor Division

The double forward slash “//“ is the floor division operator in Python. When you use this operator, Python will perform a floor division, which means the result is the quotient of the division truncated to the nearest integer towards negative infinity.

Let’s consider an example also:

Example:

5 // 2
 2

In this example, when we divide 5 by 2 using “//“, Python returns the result 2, which is the truncated integer value of the division.

Wrap Up

As a wrap up, the key difference between “/“ and “//“ in Python lies in their division behavior.

The “/“ operator performs normal division, providing a floating-point result, while the “//“ operator executes floor division, producing an integer result.