Python Division Operations

Source: Internet
Author: User
Tags floor division

The division in Python is more sophisticated than other languages and has a very complex set of rules. The division in Python has two operators,/and//

First/Division:

In Python 2.x/division is similar to most of the languages we are familiar with, such as Java AH C Ah, the result of dividing an integer is an integer, the fractional part is completely ignored, and the floating-point division retains the part of the decimal point to get the result of a floating-point number.

In Python 3.x/division no longer does this, and the result is a floating-point number for dividing between integers.

Python 2.x:

>>>0>>> 1.0/2.00.5

Python 3.x:

>>> 1/20.5

For//Division, this division, called Floor division, will automatically perform a floor operation on the result of division, consistent in Python 2.x and Python 3.x.

Floor operation: Regardless of the numeric type of the operand, the decimal part is always removed, returning the nearest number in the sequence of numbers that is smaller than the true quotient .

Python 2.x:

>>>-1//2-1

Python 3.x:

>>>-1//2-1

Python Division Operations

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.