This article mainly introduces Python division computation tips in earlier versions. There are two division operations in python2.5, namely, true division and floor Division, this article explains how to use the two methods. For more information, see Division operations in python. in python 2.5, there are two division operations, the so-called true division and floor Division. When division is performed in the form of x/y, if both x and y are integers, the result is truncated and the integer part of the operation is obtained, for example, the calculation result of 2/3 is 0. if one of x and y is a floating point number, the so-called true division will be implemented. for example, the result of 2.0/3 is 0.66666666666666663. Another division is in the form of x // y. here we use the so-called floor Division to obtain the maximum integer not greater than the result. this operation is irrelevant to the operand. For example, the result of 2 // 3 is 0, the result of-2 // 3 is-1, and the result of-2.0 // 3 is-1.0.
In the future python 3.0, x/y will only execute the true division, regardless of the operand; x // y will execute the floor Division. If you need to use python 2.5 in this way, you need to add the declaration of from _ future _ import pision before the code. For example:
The code is as follows:
From _ future _ import pision
A = 2/3
From _ future _ import pision a = 2/3
The result of variable a is 0.66666666666666663 instead of 3.