On Wed, Oct 13, 2021 at 4:56 PM Victor Stinner <vstin...@python.org> wrote:

> Honestly, I don't understand well the difference between __int__() and
> __index__().
>
> * https://docs.python.org/dev/reference/datamodel.html#object.__int__
> * https://docs.python.org/dev/reference/datamodel.html#object.__index__
>

If you want to index a list or array 'a' with index 'i', and i is not an
int already, we try to convert it to int using __index__. This should fail
for floats, since a[3.14] is a bug. OTOH, int(x) where x is a float should
work, and that's where __int__ is used. And int(s) where s is a string
should also work, so int() can't call __trunc__ (as was explained earlier
in the thread).

-- 
--Guido van Rossum (python.org/~guido)
*Pronouns: he/him **(why is my pronoun here?)*
<http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/DDADEDENVVWC3JJNAR4LS6WGUUC63EUS/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to