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

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

    Python 2.x Clarification:

    To clarify for the Python 2.x line, / is neither floor division nor true division. The current accepted answer is not clear on this.

    / is floor division when both args are int, but is true division when either or both of the args are float.

    The above tells more truth, and is more clear than the 2nd paragraph in the accepted answer.

提交回复
热议问题