NamedTuple & Enum

Introduction

When building projects in Python, it can be useful to define custom data types that can be combined together in various ways.

Composition

One way to combine custom data types is by using composition, which involves creating a new class that contains instances of other classes as attributes.

For example, if you have a class for a "Person" that contains attributes like name and age, and a class for a "Job" that contains attributes like title and salary, you could combine them by creating a new class called "Employee" that contains instances of both the "Person" and "Job" classes as attributes.

Inheritance

Another way to combine custom data types is by using inheritance, which involves creating a new class that is a subclass of two or more existing classes. This allows the new class to inherit attributes and methods from each of the parent classes.

For example, you could create a class called "JobStudent" that is a subclass of both the "Job" and "Student" classes. This would allow instances of the "JobStudent" class to have attributes and methods from both parent classes.

When combining custom data types, it is important to carefully consider the relationships between the classes and how they will be used in your project. By using composition and inheritance effectively, you can create powerful and flexible custom data types that can be used to represent complex real-world objects in your Python projects.