After reading lesson 5, you’ll be able to
- Write code that creates various types of objects
- Write simple lines of code to manipulate Python variables
Suppose you have a family as follows:
- Four people—Alice, Bob, Charlotte, and David
- Three cats—Priss, Mint, and Jinx
- Two dogs—Rover and Zap
Every person, cat, and dog is a separate object. You named each object something different so you can easily refer to them and so that everyone else knows which object you’re talking about. In this family, you have three types of objects: people, cats, and dogs.
Each type of object has characteristics that are different from another type. People have hands and feet, whereas cats and dogs have only feet. Cats and dogs have whiskers, but people don’t. The characteristics of a type of object uniquely identify all individual objects in that type. In programming, characteristics are called data attributes, or values, for the type.
Each type of object also has actions or behavior. People can drive a car, but dogs and cats can’t. Cats can climb trees, but dogs can’t. The actions that a type of object can do are specific to that object only. In programming, actions are called operations on the type.