Think Python 4.1: Why does printing bob give me an object rather than an instance?
<p>All other answers on stackoverflow about instances vs. objects refer to classes, which the book hasn't covered yet.
This is the code:</p>

<pre><code>world= TurtleWorld()
bob= Turtle()
print bob
wait_for_user()
</code></pre>

<p>and this is the result:</p>

<p>It shows the turtle in a box, and prints</p>

<pre><code>&lt;swampy.TurtleWorld.Turtle object at 0x03C3D730&gt;
</code></pre>

<p>The book says it should say 'instance', not object. What's the difference, and what am I doing wrong?</p>

<p>You have an instance; an instance is a <em>kind</em> of Python object. If you didn't have an instance, you'd see something different:</p>

<pre><code>&lt;class 'swampy.TurtleWorld.Turtle'&gt;
</code></pre>

<p>Now, in Python 2 using old-style classes, it would indeed have said <code>instance</code>; I can create such an object by <em>not</em> inheriting from <code>object</code>:</p>

<pre><code>&gt;&gt;&gt; class Turtle: pass
...
&gt;&gt;&gt; Turtle()
&lt;__main__.Turtle instance at 0x10199fe18&gt;
</code></pre>

<p>However, the current <a href="http://www.greenteapress.com/thinkpython/swampy/" rel="nofollow">swampy release</a> uses <em>new-style classes</em>; where the class inherits from <code>object</code>:</p>

<pre><code>&gt;&gt;&gt; from swampy.TurtleWorld import Turtle
&gt;&gt;&gt; Turtle.__mro__
(&lt;class 'swampy.TurtleWorld.Turtle'&gt;, &lt;class 'swampy.World.Animal'&gt;, &lt;type 'object'&gt;)
</code></pre>

<p>New-style classes do things a little different, and some things have been renamed and unified. I think you are using the first edition of Think Python, based on code not using new-style classes. </p>

<p>You can probably complete your tutorial with only minor cosmetic changes like these showing up. </p>

<p>However, you may want to find a newer, more recent book; Think Python has a 2nd edition using Python 3, for example.</p>

python python-2.7 oop