Duck typing 2026-11-05
Duck typing uses an object's available operations as the practical interface required by a piece of code, rather than demanding membership in one particular class. The Python glossary describes calling the needed method or using the needed attribute directly. This supports flexible reuse across unrelated implementations.[ref]
Glossary, Python 3.14 documentation. duck-typing entry
For example, a procedure calling
source.read() can accept a disk-backed file object or an in-memory object providing a compatible read method. Sharing that method name is insufficient if one method returns text while the procedure requires bytes, or if their error behavior differs. The required interface includes semantics as well as names. Duck typing is commonly used with dynamic typing, but it does not imply that missing or incompatible operations become valid. Dynamic typing 2026-11-05
With dynamic typing, the types of values determine the operations permitted during execution, while a variable name can be rebound to values of different types. This differs from changing the type of one existing value. In Python,
x=3; x="three" rebinds the name; the integer object has not become a string.[ref]Python 3.14 Data Model. §3.1, Objects, values and types
A call can succeed for several classes if each supplies the operations the function actually uses. This is often called duck typing: a function iterating over its argument can accept different iterable objects. An unsupported operation still fails when reached. Dynamic typing does not imply absence of a type system, automatic conversion between every pair of types, or that every error waits until execution; syntax errors and some other checks can occur earlier.
Python (programming language) Created 2026-10-13 Updated 2026-11-05
Python is a general-purpose programming language with dynamic typing, functions, software classes, exception handling and modules. It supports procedural, object-oriented programming and functional programming. Guido van Rossum developed it to combine readable high-level data types with extensibility and access to operating system facilities; he began the implementation in 1989 and released it publicly in 1991.[ref]
General Python FAQ. What is Python? and Why was Python created in the first place?
The standard-library
ast module exposes Python abstract syntax trees. For example, parsing 2 + 3 * 4 in expression mode produces an addition whose right operand is a multiplication: the tree records operator precedence, and ordinary integer arithmetic evaluates the expression to 14. The abstract syntax tree can be inspected or transformed before compilation. The tree examples here use the Python 3.14 schema, since the schema can change between language versions.[ref]