SoFunction
Updated on 2024-11-16

Analyzing True Division and Floor Division Usage in Python 3

This article is an example of true division and Floor division usage in Python3. It is shared for your reference as follows:

In Python 3, there are two types of division operations, one is True Division and the other is Floor Division, which are separate, respectively, as shown in the code:

>>>10/4
2.5
>>>10//4
2
>>>10/4.0
2.5
>>>10//4.0
2.0

A slash division in Python 3 is a true division, which is the same as in other programming languages, preserving floats, and a Floor division is a division that removes floats to preserve integers, hence the name Floor division.

Give an example of when to use Floor division.

xSize, ySize = 
fontSize = min(xSize, ySize) // 11
myFont = ("/Library/Fonts/", fontSize)

Here xSize and ySize represents the width and height of the image pixels, fontSize for the font size must be passed into the integer, so the Floor used here divided by 11 to find the integer, as can be seen from this code fontSize is the width of the high school is smaller than a shrinking of 11 the proportion of the integer.

I hope that what I have said in this article will help you in Python programming.