[Python-Dev] Semantics of __int__(), __index__()
dickinsm at gmail.com
Sat Apr 6 22:34:19 CEST 2013
On Fri, Apr 5, 2013 at 6:34 PM, Terry Jan Reedy <tjreedy at udel.edu> wrote:
> 2. int(rational): for floats, Fractions, and Decimals, this returns the
> integral part, truncating toward 0. Decimal and float have __int__ methods.
> Fractions, to my surprise, does not, so int must use __floor__ or __round__
> as a backup.
It uses __trunc__, which is supposed to be the unambiguous "Yes I really
want to throw away the fractional part and risk losing information"
replacement for __int__. int() will try __int__ first, and then __trunc__,
as per PEP 3141.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev