Why is the integer division of Python accurate???

Source: Internet
Author: User
Tags integer division

In Python, there are two types of division, one of which is / :

>>> 10 / 3

3.3333333333333335

/The division evaluates to a floating-point number, even if it is exactly divisible by two integers, and the result is a floating-point number:
>>> 9 / 33.0

There is also a division that is // called a floor divide, where the division of two integers is still an integer:

>>> 10 // 3

3

You are not mistaken, the whole number of floors apart // is always an integer, even if not endless.

To do the exact division, you / can use it. Because // division takes only the integer part of the result.


Python also provides a remainder operation that can be used to divide the remainder of two integers:

>>> 10 % 31


The result is always an integer, regardless of whether the integer // divides or takes the remainder, so the result of the integer operation is always accurate.

Why is the integer division of Python accurate???

Related Article

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.