Analysis on the use of truth division and Floor Division in Python3

Source: Internet
Author: User
Tags floor division
This article mainly introduces the use of truth division and Floor Division in Python3, and analyzes the differences between truth division and Floor division based on the instance form, if you need it, refer to the example in this article to describe the use of real division and Floor Division in python3. We will share this with you for your reference. The details are as follows:

In Python3, there are two division operations: real division and Floor division. The two are classified, as shown in the code:

>>> 10/42. 5 >>>> 10 // 42 >>> 10/4. 02.5 >>>> 10 // 4.02.0

The division of a slash in Python3 is the real division, which is the same as that in other programming languages. the floating point is retained, and the Floor Division is the division that removes the floating point and retains the integer. Therefore, it is called the Floor Division.

For example, when should Floor Division be used.

XSize, ySize = avatar. sizefontSize = min (xSize, ySize) // 11 myFont = ImageFont. truetype ("/Library/Fonts/mongokamono. ttf", fontSize)

Here, xSize and ySize indicate the width and height of the image. fontSize indicates the font size, which must be an integer. Therefore, the Floor is divided by 11 to calculate the integer, from this code, we can see that fontSize is an integer smaller than width, high school, and a smaller proportion to 11.

For more details about the usage and analysis of real division and Floor Division in Python3, please follow the PHP Chinese network!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.