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

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

    As everyone has already answered, // is floor division.

    Why this is important is that // is unambiguously floor division, in all Python versions from 2.2, including Python 3.x versions.

    The behavior of / can change depending on:

    • Active __future__ import or not (module-local)
    • Python command line option, either -Q old or -Q new

提交回复
热议问题