title: Understanding __getitem__ method
body: <p>I have gone through most of the documentation of <code>__getitem__</code> in the Python docs, but I am still unable to grasp the meaning of it.</p>
  
  <p>So all I can understand is that <code>__getitem__</code> is used to implement calls like <code>self[key]</code>. But what is the use of it?</p>
  
  <p>Lets say I have a python class defined in this way:</p>
  
  <pre><code>class Person:
      def __init__(self,name,age):
          self.name = name
          self.age = age
  
      def __getitem__(self,key):
          print ("Inside `__getitem__` method!")
          return getattr(self,key)
  
  p = Person("Subhayan",32)
  print (p["age"])
  </code></pre>
  
  <p>This returns the results as expected. But why use <code>__getitem__</code> in the first place? I have also heard that Python calls <code>__getitem__</code> internally. But why does it do it?</p>
  
  <p>Can someone please explain this in more detail?</p>