Why Python 3?
Marko Rauhamaa
marko at pacujo.net
Sat Apr 19 05:59:18 EDT 2014
Ian Kelly <ian.g.kelly at gmail.com>:
> On Sat, Apr 19, 2014 at 1:34 AM, Chris Angelico <rosuav at gmail.com> wrote:
>> if you're going to move to Python 3, you may as well have your code
>> start working that way, so you get used to typing // to divide
>> integers and get an integer (floor division).
>
> [...]
>
> We also gained a consistent and explicit way to differentiate between
> the two different styles of division that classic division
> represented, as opposed to picking at run-time based on type.
Very often when integer division is needed, so is the remainder. Then,
it is good to remember the builtin divmod() function:
https://docs.python.org/3.4/library/functions.html#divmod
In fact, divmod() goes a long way toward removing the need for // and %
in Python code.
Marko
More information about the Python-list
mailing list