The first thing to say about division in Python is that there are two division operations in the Python 2.5 version, known as True division and floor division. When you use the X/y form for division operations, if X and Y are all shaped, then the operation will intercept the results, take the integer part of the operation, such as 2/3 of the operation result is 0; if one of the X and Y is a floating-point number, then the so-called true division is performed, for example, the result of 2.0/3 is 0.66666666666666663. Another kind of division is in the form of x//y, so here is the so-called floor division, which is not the result of the maximum integer value, this operation is independent of the operand. For example, the result of 2//3 is that the result of 0,-2//3 is -1,-2.0//3 1.0.
In the future of Python 3.0, x/y will perform only true division, regardless of operand, and x//y perform floor division. If you need to use this in version 2.5 Python, you need to add a declaration from the __FUTURE__ import division before your code. Such as:
Copy Code code as follows:
From __future__ Import Division
A=2/3
From __future__ Import Division A=2/3
Then the result of variable a will be 0.66666666666666663, not the original 3.