An object behavior is an operation that defines how objects of a type can act or interact. A calculator performs mathematical operations, while a cat might scratch, hide, or sleep. Properties describe what an object has; behaviors describe what it can do. section 30.0 section 30.2
When designing an object type, choose behaviors that represent useful interactions:
- A car can change color, make a noise, or turn its wheels. section 30.2
- A circle can report its area or circumference. section 30.2
- A map point can identify its country or calculate distance from another point. section 30.2
- A room can add an item, making interaction with its stored objects explicit. section 30.2
Behavior through a class
A Python class packages properties and behaviors into one reusable object type. For a queue, properties can hold its items, while behaviors can get its size, add one or many items, remove one or many items, and display the queue. A program can then create queue objects and perform a sequence of operations on them. section 31.0 section 32.3
Objects of the same type share the behaviors defined for that type. In Python, dot notation commonly accesses an object's behaviors, such as list operations including append, extend, pop, index, and remove; number operations commonly use mathematical symbols instead. section 30.4 section 31.0



