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

后端 未结 13 2408
孤独总比滥情好
孤独总比滥情好 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:36

    The answer of the equation is rounded to the next smaller integer or float with .0 as decimal point.

    >>>print 5//2
    2
    >>> print 5.0//2
    2.0
    >>>print 5//2.0
    2.0
    >>>print 5.0//2.0
    2.0
    

提交回复
热议问题