[python] How to override the [] operator in Python?

What is the name of the method to override the [] operator (subscript notation) for a class in Python?

This question is related to python operator-overloading

The answer is


To fully overload it you also need to implement the __setitem__and __delitem__ methods.

edit

I almost forgot... if you want to completely emulate a list, you also need __getslice__, __setslice__ and __delslice__.

There are all documented in http://docs.python.org/reference/datamodel.html


You are looking for the __getitem__ method. See http://docs.python.org/reference/datamodel.html, section 3.4.6