For supporting operations like obj[key], the class should define the _______ method.

  • __getitem__
  • __getkey__
  • __getvalue__
  • __index__
To support operations like obj[key] for custom objects, you should define the __getitem__ method in the class. This method is called when you use square brackets to access an item in the object.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *