What is the division operator in python? There are two types of division operators in python, one is the floating point division operator and the other is the integer division operator.
1. /
Floating point division, even if the numerator and denominator are both int types, the float type will be returned. For example, if we use 4/2, it will return 2.0
2. //
Integer division, the returned value is different depending on the different combinations of numerator and denominator.
Related recommendations: "Python Video Tutorial"
Positive numbers//Positive numbers, rounded, such as 5//3, return 1
Positive numbers //Negative numbers, round down, such as 5//-3, return -2. Note that the upper and lower here are relative, because -2 is smaller than -1.6, so we can Understand rounding down.
Negative numbers //Positive numbers, round down, same as positive numbers //Negative numbers, such as -5//3, return -2
Negative numbers //Negative numbers, rounded, such as -5//-3, return 1
In summary, we can conclude, // To be more precise, this division should be called rounding down, that is, taking/dividing the smaller actual value. If the value is a positive number, take the integer digit. If the result is a negative number, take the result after the integer digit -1. If the actual result If it is a float type, ".0" will be added to the return value, that is, the inverse float value is returned.
The above is the detailed content of What is the division operator in python. For more information, please follow other related articles on the PHP Chinese website!