← Back to all posts
Integer division

What does double slash do in python, and what is integer division?

joshhies (168)

basically the `//` is floor division. It just like you devides something and the round the result.

Upvote if you like it.

rediar (134)

It divides it and rounds it down.
11//3=3

NSCarter (3)

`//` is floor division. This means that when you divide two integers it rounds it down to a whole number e.g.
`10 / 3 = 3.33333...`
but
`10 // 3 = 3`

Integer division is where the remainder from a division is disregarded e.g. 3.333 would become 3

ImiekameLonge (1)

@NSCarter Thanks for the clairification!

olafh10 (31)

In programming, there are two types of divisions; integer division and float division. Integer stands for a solid number (like 1, 2, 3, 4 etc), while a float is a number with a decimal part (1.0, 1.2, 1.3, 1.438345 etc)

Python 2 tried to keep an integer an integer, and a float a float. Thus, you could only get a float result by having a float in your division:
(Python 2):

``````>>> 10.0/3
3.3333333333333335
>>> 10/3
3``````

See? In the second calculation the result is rounded to a whole number in order that it counts as an integer.

Python 3 changed this. In order to make it (logically) easier, they stopped trying to give you a integer back if you input an integer:
(Python 3):

``````>>> 10/3
3.3333333333333335``````

But, sometimes you WANT a number to be rounded for some reason. To give you the possibility to still do that, Python introduced the `//` operator in Python 3. This operator does what Python 2 would do when trying to divide with integers:
(Python 3):

``````>>> 10//3
3``````

If you want a pretty technical explanation along with arguments, check out PEP0238 (The archive case for this feature)