title: Square brackets applied to "self" in Python
body: <p>I've come across some code where square brackets are used on "self". I'm not familiar with this notation and as I'm trying to get my head around source code not written by me, it makes it difficult to understand what sort of object is being dealt with here.</p>
  
  <p>The example I've come across is in the Natural Language Toolkit for Python <a href="http://nltk.org/_modules/nltk/model/ngram.html" rel="noreferrer">here</a>. You can find an example of what I mean if you ctrl-F <code>self[context]</code>.</p>
  
  <p>It may not be possible to tell exactly how it's being used without more context, but here's a snippet with an example:</p>
  
  <pre><code>context = tuple(context)
  if (context + (word,) in self._ngrams) or (self._n == 1):
       return self[context].prob(word)
  else:
       return self._alpha(context) * self._backoff.prob(word, context[1:])
  </code></pre>