title: How do you set up the __contains__ method in python?
body: <p>I'm having trouble understanding how to properly set up a <strong>contains</strong> method in my class. I know it automatically uses the operator "in" when you call it, i just don't think I understand how to set it up correctly.</p>
  
  <p>I have to use it to see if anotherCircle is contained within a specific circle (both input from the user). The prof had us do two different types of methods for this.</p>
  
  <p>The first one I have no problems with and more or less understand what it is doing, It is as follows:</p>
  
  <pre><code>def contains(self, circle2d):
    dist = math.sqrt((circle2d._x - self._x)**2 + (circle2d._y - self._y)**2) #Distance of second circle's coords from the first circle's coords
    if dist + circle2d._radius &lt;= self._radius:
       return True
  </code></pre>
  
  <p>However, the next method, which is supposed to do the same thing, uses the <strong>contains</strong> method so that we can call it with <strong>in</strong> in the main function. All I have is this:</p>
  
  <pre><code>def __contains__(self, anotherCircle):
      if anotherCircle in self:
          return True 
  </code></pre>
  
  <p>I get multiple errors when I try to run this. I think i'm missing something on self, but I'm not sure what? Could someone please try to explain to me what exactly you need to do when you're writing a <strong>contains</strong> method such as this?</p>