title: How to print instances of a class using print()?
body: <p>When I try to <code>print</code> an instance of a class, I get an output like this:</p>
  <pre><code>&gt;&gt;&gt; class Test():
  ...     def __init__(self):
  ...         self.a = 'foo'
  ...
  &gt;&gt;&gt; print(Test())
  &lt;__main__.Test object at 0x7fc9a9e36d60&gt;
  </code></pre>
  <p>How can I can define the <em>printing behaviour</em> (or the <em>string representation</em>) of a class and its instances? For example, referring to the above code, how can I modify the <code>Test</code> class so that <code>print</code>ing an instance shows the <code>a</code> value?</p>