indexing - Examples of Python Objects That Have An __index__() method? -
what examples of python objects have __index__() method other int?
for example, hex documentation state:
if
xnot python int object, has define__index__()method returns integer.
this self-learning.
mostly, these types mathematical libraries numpy or sympy. these libraries have own integer types (for reason), __index__, special integers can used list indices or passed hex normal integers.
in [9]: import sympy in [10]: x = sympy.integer(1) in [11]: x # looks regular 1, it's not. out[11]: 1 in [12]: x/2 # object has special behavior makes sense sympy... out[12]: 1/2 in [13]: [1, 2, 3][x] # can still use things indexing. out[13]: 2
Comments
Post a Comment