Composition in Python classes: The has-a relationship

Composition in Python classes: The has-a relationship

Creating a Python class? You’re already using composition, the has-a relationship.

How?

When you assign to an attribute (e.g., self.name = name) in a Person class, you’re saying, “Person has-a name”. name could be a builtin str, or an instance of a custom PersonName class.