Home  >  Article  >  Backend Development  >  What is the division operator in python

What is the division operator in python

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-06-20 16:45:428875browse

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.

What is the division operator in python

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

What is the division operator in python

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

What is the division operator in python

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.

What is the division operator in python

Negative numbers //Positive numbers, round down, same as positive numbers //Negative numbers, such as -5//3, return -2

What is the division operator in python

Negative numbers //Negative numbers, rounded, such as -5//-3, return 1

What is the division operator in python

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn