Operator Functions

operator.index()

Request an exact integer index via the index protocol; floats are not truncated. Since 3.10 the result has exact type int.

Formal Syntax & Structure

python syntaxpython
operator.index(a, /)

Parameters & Attributes

NameTypeDescription
aobjectLeft operand or target object.

Return Value

int

The int result described above.

Working Example

Example Snippetpython
import operatorclass Index: def __index__(self): return 4print(operator.index(Index()))
Python Reference