What is the difference between '/' and '//' when used for division?

后端 未结 13 2159
孤独总比滥情好
孤独总比滥情好 2020-11-21 07:23

Is there a benefit to using one over the other? In Python 2, they both seem to return the same results:

>>> 6/3
2
>>> 6//3
2
13条回答
  •  一整个雨季
    2020-11-21 07:43

    The above answers are good. I want to add another point. Up to some values both of them result in the same quotient. After that floor division operator (//) works fine but not division (/) operator.

     - > int(755349677599789174/2)
     - > 377674838799894592      #wrong answer
     - > 755349677599789174 //2
     - > 377674838799894587      #correct answer
    

提交回复
热议问题