On Dec 14, 1:38 pm, Steven D'Aprano <steve +comp.lang.pyt...@pearwood.info> wrote: > On Wed, 14 Dec 2011 02:09:32 -0800, Eelco wrote: > > Arguably, the most elegant thing to do is to define integer division and > > remainder as a single operation; which is not only the logical thing to > > do mathematically, but might work really well programmatically too. > > > The semantics of python dont really allow for this though. One could > > have: > > > d, r = a // b > > That would be: > > >>> divmod(17, 5) > > (3, 2)
Cool; if only it were in the math module id be totally happy. > > But it wouldnt work that well in composite expressions; selecting the > > right tuple index would be messy and a more verbose form would be > > preferred. However, performance-wise its also clearly the best solution, > > as one often needs both output arguments and computing them > > simultaniously is most efficient. > > Premature optimization. We are talking language design here, not language use. Whether or not this is premature is a decision that should be left to the user, if at all possible, which in this case it very well is; just provide multiple functions to cover all use cases (only return divisor, only return remainder, or both) -- http://mail.python.org/mailman/listinfo/python-list