What is the term for Python's dynamic type system where behavior is determined by the object's methods?

The story behind the answer

The term for Python's method-based dynamic type system is duck typing. An object is accepted according to the operations it supports, rather than because it belongs to a particular named class or explicitly implements an interface.

The name comes from the “duck test”: if something walks and quacks like a duck, it can be treated as a duck for the task at hand. In Python, a function might accept any object that provides the methods it needs. A file-like object, for example, need not inherit from Python's file classes if it supplies compatible methods such as `read()`.

Duck typing encourages Python's EAFP style—“it’s easier to ask forgiveness than permission”—where code attempts an operation and handles an appropriate exception instead of checking types first. It is related to structural typing, but structural typing commonly checks compatibility statically, while duck typing makes the relevant decision during execution. “Strong typing” describes a different property and is not the answer here.

Source: Wikipedia · fact-checked Aug. 2026

Add question to a list

Choose a list to keep this question in: