From the course: Learning SOLID Programming Principles
Unlock the full course today
Join today to access over 24,500 courses taught by industry experts.
Duck Typing - Python Tutorial
From the course: Learning SOLID Programming Principles
Duck Typing
- The Python language does not require a formal definition of an abstract super class. And while it often makes sense to use the abc module to define super classes for abstractions, we have two alternatives. I like to call these "informal subclassing". Because of Python's duck typing, it's not essential to have a single abstract super class. Duck typing means the code doesn't have to follow a strict inheritance hierarchy. If you haven't heard the term "duck typing" before, it comes from this: When I see a bird that walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck. If two Python objects have the same methods and attributes, well, then for all practical purposes in Python they may as well be members of the same class. Python doesn't rely on the declared type, but on the presence of methods and attributes. Tools like mypy will check to confirm that classes used interchangeably really…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.