An analysis of the usage of true division and Floor division in detailed Python3

Source: Internet
Author: User
Tags floor division
This example describes the use of true and floor division in Python3. Share to everyone for your reference, as follows:

In Python3, there are two kinds of division operations, one is true, the other is floor division, and the two are separate, 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 true except that it is the same as other programming languages, preserving floating-point numbers, and floor division is a division that removes floating-point numbers to preserve integers, so called floor division.

As an example, when to use floor division.

Xsize, ysize = avatar.sizefontsize = Min (xsize, ysize)//11myFont = Imagefont.truetype ("/library/fonts/osakamono.ttf", F Ontsize)

Here Xsize and ysize represent the width and height of the image, FontSize must pass in an integer for the font size, so the floor here is divided by 11 for integers, and from this code it can be seen that fontsize is an integer that is smaller by 11 of the width of high school.

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.