/ vs. // operator in Python

Python is a high-level programming language that can be used to build websites, software, machine-learning models, etc. Different operators are provided in Python that tell the interpreter to perform a specific task, such as division, multiplication, etc.

In this Answer, we will compare the regular division operator / and the floor division operator // to see how they differ from one another.

Regular division operator ( / )

The / operator refers to the regular division operator. It performs division on two variables and returns the output as a float.

Regular division example
Regular division example

The / operator will always return a float value whether we give it two integers or float variables as operator arguments.

Below, we can see a Python code example that uses the / operator.

# division between two integers
result = 10 / 3
print("10 / 3 = " + str(result), end = "\n\n")
# division between a float and a integer
result = 2.5 / 2
print("2.5 / 2 = " + str(result), end = "\n\n")
#division between two floats
result = 5.5 / 2.3
print("5.5 / 2.3 = " + str(result), end = "\n\n")

Floor division operator ( // )

The // operator refers to the floor division operator. It takes two variables as input, either integers or floats. It then returns the result of their division rounded to the nearest whole number towards negative infinity. For example, 0.67 would be rounded to 0 instead of 1.

Floor division example
Floor division example

The floor division operator always returns an integer value if both inputs are integers and a float value if either input is a float.

Below are Python code examples that perform floor division using the // operator.

# division between two integers
result = 10 // 3
print("10 // 3 = " + str(result), end = "\n\n")
# division between a float and a integer
result = 2.5 // 2
print("2.5 // 2 = " + str(result), end = "\n\n")
#division between two floats
result = 5.5 // 2.3
print("5.5 // 2.3 = " + str(result), end = "\n\n")

Conclusion

The regular division operator is used when we want to perform normal division on numbers where we want the fractional part of the answer. We use the floor division operator when we want to get the result of the division operation rounded down to the nearest number towards negative infinity.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved