During Python's evolution, the term protocol became overloaded with two subtly different meanings. The first meaning refers to internal protocols, such as the iterator, context manager, and descriptor protocols. These protocols are widely understood in the community and consist of special methods that make up a given protocol.
Python 3.8 introduced a second, slightly different type of protocol, specifying the methods and attributes that a class must implement to be considered of a given type. This allows defining interchangeable classes with a common internal structure, enforcing a relationship between types/classes without inheritance.
Python is dynamically typed, with the interpreter checking an object's type at runtime. This dynamic nature allows for a flexible typing system known as duck typing, where an object is compatible with a type based on having the required methods and attributes.
Collection
[
|
...
]