After reading lesson 31, you’ll be able to
- Define a Python class
- Define data properties for a class
- Define operations for a class
- Use a class to create objects of that type and perform operations
You can create your own types of objects to suit whatever your program needs. Except for atomic object types (int, float, bool), any object that you create is made up of other preexisting objects. As someone who implements a new object type, you get to define the properties that make up the object and the behaviors that you’ll allow an object to have (on its own or when interacting with other objects).
You usually define your own objects in order to have customized properties and behaviors, so that you can reuse them. In this lesson, you’ll view code you write from two points of view, just as when you wrote your own functions. You’ll separate yourself from a programmer/writer of a new object type and from the programmer/user of a newly created object type.
Before defining an object type by using a class, you should have a general idea of how you’ll implement it by answering two questions:
- What is your object made up of (its characteristics, or properties)?
- What do you want your object to do (its behaviors, or operations)?