Skip to content
Home » True Division vs Floor Division in Python

True Division vs Floor Division in Python

Spread the love

Today we’ll be talking about the difference between true division and floor division in Python.

There are two kinds of division operators:

1) true division /

2) floor division //

In true division the result of dividing two integers is a float:

>>> 12 / 4
3.0
>>> 20 / 3
6.666666666666667

In floor division the result is truncated down, so the result is the floor – the largest integer number smaller than the result of true division:

>>> 12 // 4
3
>>> 20 // 3
6

If either the dividend or the divisor or both are floats, the result is a float. If both are integers, the result is an integer:

>>> 10 // 5         # int // int -> int
2

>>> 10 // 3         # int // int -> int
3

>>> 10.0 // 3       # float // int -> float
3.0

>>> 10 // 3.0       # int // float -> float
3.0

>>> 10.0 // 3.0     # float // float -> float
3.0

>>> 5.6 // 2        # float // int -> float
2.0

Your Panda3D Magazine

Make Awesome Games and Other 3D Apps

with Panda3D and Blender using Python.

Cool stuff, easy to follow articles.

Get the magazine here (PDF).

Python Jumpstart Course

Learn the basics of Python, including OOP.

with lots of exercises, easy to follow

The course is available on Udemy.

Blender Jumpstart Course

Learn the basics of 3D modeling in Blender.

step-by-step, easy to follow, visually rich

The course is available on Udemy and on Skillshare.

Here’s the video version:


Spread the love

Leave a Reply