What is the difference between the __int__ and __index__ methods in Python 3?

See PEP 357: Allowing Any Object to be Used for Slicing.

The nb_int method is used for coercion and so means something
fundamentally different than what is requested here. This PEP
proposes a method for something that can already be thought of as
an integer communicate that information to Python when it needs an
integer. The biggest example of why using nb_int would be a bad
thing is that float objects already define the nb_int method, but
float objects should not be used as indexes in a sequence.

Edit: It seems that it was implemented in Python 2.5.

Leave a Comment

techhipbettruvabetnorabahisbahis forumueduseduedusedusedueduseduedueduedus