% is not an operator [was Re: Verbose and flexible args and kwargs syntax]
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Wed Dec 14 07:38:31 EST 2011
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)
> 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.
--
Steven
More information about the Python-list
mailing list