Skip to main content

Section 13.3 Objects Revisited

In Python, every value is actually an object. Whether it be a string, a list, or even an integer, they are all objects. Programs manipulate those objects either by performing computation with them or by asking them to perform methods. To be more specific, we say that an object has a state and a collection of methods that it can perform. The state of an object represents those things that the object knows about itself.
A good way to investigate objects is with turtle graphics, which is based on a very simple metaphor. Imagine that you have a turtle that understands English. You can tell your turtle to do simple commands such as go forward and turn right. As the turtle moves around, if its tail is down touching the ground, it will draw a line (leave a trail behind) as it moves. If you tell your turtle to lift up its tail it can still move around but will not leave a trail. It is possible to make some pretty amazing drawings with this simple capability.
Each turtle has a state consisting of the turtle’s position, its color, its heading and so on. Each turtle also has methods that give it the ability to go forward, backward, or turn right or left. Individual turtles are different in that even though they are all turtles, they differ in the specific values of the individual state attributes (maybe they are in a different location or have a different heading).