Duck typing

In computer programming, duck typing is an application of the duck test—"If it walks like a duck and it quacks like a duck, then it must be a duck"—to determine whether an object can be used for a particular purpose. With nominative typing, an object is of a given type if it is declared as such (or if a type's association with the object is inferred through mechanisms such as object inheritance). With duck typing, an object is of a given type if it has all methods and properties required by that type.[1][2] Duck typing may be viewed as a usage-based structural equivalence between a given object and the requirements of a type.

  1. ^ "Glossary — Python 3.7.1 documentation". docs.python.org. Retrieved 2018-11-08.
  2. ^ "Python Duck Typing - Example". Techie Hours. 2020-06-28. Archived from the original on 2022-03-31. Retrieved 2020-07-26.