In Python, when doing division, you can use both // and / to divide numbers. // means floor or integer division, and / means floating point division.
print(10/3)
print(10//3)
#Output:
3.333333333333335
3
In Python, we can perform division of numbers in different ways. You can use both // and / to divide numbers
The difference between // and / is that // performs floor division, and / performs floating point division.
Floating point division is regular division, and floor division truncates the resulting quotient.
Below are a few examples of the difference between // and / in Python.
print(10/3)
print(10//3)
print(93/4)
print(93//4)
#Output:
3.333333333333335
3
23.25
23
Performing Floor Division in Python with //
In Python, floor division, or integer division, is the division of two numbers and returning the quotient as a truncated integer value.
Below are a few examples of floor division in Python with a double slash //.
print(10//3)
print(93//4)
#Output:
3
23
Notice here that if you divide a double by an integer with a double slash //, the return value is a double.
print(10.0//3)
print(10//3)
#Output:
3.0
3
Hopefully this article has been useful for you to learn how to understand the difference between // and /, and be able to do division with both single slashes (/) and double slashes (//) in Python.