Alex Rivera | Logout

How to override the [] operator in Python?

Asked 2009-12-24T10:35:24.340
363

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

Edit
Report

1 Answer

25

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

answered 2009-12-24T10:38:25.030

Your Answer