Python 3 int division operator is returning a float?

前端 未结 2 1925
天命终不由人
天命终不由人 2020-12-20 23:01

In one of my assignments I came across a weird implementation, and I was curious if it\'s a bug or the designed behavior.

In Python 3, division by / ret

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-20 23:33

    I hope this clarifies the situation:

    / Division

    Divides left hand operand by right hand operand

    b / a = 2
    

    // Floor Division

    The division of operands where the result is the quotient in which the digits after the decimal point are removed. But if one of the operands is negative, the result is floored, i.e., rounded away from zero (towards negative infinity)

    9//2 = 4 and 9.0//2.0 = 4.0, -11//3 = -4, -11.0//3 = -4.0
    

    https://www.tutorialspoint.com/python/python_basic_operators.htm

提交回复
热议问题