Loading...

In Python, there are two kinds of division: integer division and float division.

Python 2 syntax

from __future__ import division

# floating point division
print 4 / 3

# integer division  
print 4 // 3

Python 3 syntax

print(4 / 3)
print(4 // 3)

Gives the output

1.3333333333333333 
1

Note: The __ in __future__ is a double underscore.

During the time of Python 2, when you divided one integer by another integer, no matter what, the result would always be an integer.

For example:

>>> 4/3 
1

In order to make this a float division, you would need to convert one of the arguments into a float.

For example:

>>> 4/3.0
1.3333333333333333

Since Python doesn't declare data types in advance, you never know when you want to use integers and when you want to use a float. Since floats lose precision, it's not advised to use them in integral calculations.

To solve this problem, future Python modules included a new type of division called integer division given by the operator //.

Now, / performs float division, and // performs integer division.

In Python 2, we will import a feature from the module __future__ called division.

Solve Problem