Special Method Protocols

__int__() — numeric protocol

Provide an integer conversion, not necessarily an exact index. int() may fall back to __index__, and in 3.13 its __trunc__ fallback is deprecated. The hook must return the specified numeric type.

Formal Syntax & Structure

python syntaxpython
def __int__(self):

Return Value

int

Converted numeric value.

Working Example

Example Snippetpython
import operatorclass Number:    def __init__(self, value):        self.value = value    def __int__(self):        return int(self.value)print(int(Number(3.75)))
Python Reference