title: Compare object instances for equality by their attributes
body: <p>I have a class <code>MyClass</code>, which contains two member variables <code>foo</code> and <code>bar</code>:</p>
  
  <pre><code>class MyClass:
      def __init__(self, foo, bar):
          self.foo = foo
          self.bar = bar
  </code></pre>
  
  <p>I have two instances of this class, each of which has identical values for <code>foo</code> and <code>bar</code>:</p>
  
  <pre><code>x = MyClass('foo', 'bar')
  y = MyClass('foo', 'bar')
  </code></pre>
  
  <p>However, when I compare them for equality, Python returns <code>False</code>:</p>
  
  <pre><code>&gt;&gt;&gt; x == y
  False
  </code></pre>
  
  <p>How can I make python consider these two objects equal?</p>