abstract base classes while duck typing is usefulit is not always easy to tell in advance if class is going to fulfill the protocol you require thereforepython introduced the idea of abstract base classes abstract base classesor abcsdefine set of methods and properties that class must implement in order to be considered duck-type instance of that class the class can extend the abstract base class itself in order to be used as an instance of that classbut it must supply all the appropriate methods in practiceit' rarely necessary to create new abstract base classesbut we may find occasions to implement instances of existing abcs we'll cover implementing abcs firstand then briefly see how to create your own if you should ever need to using an abstract base class most of the abstract base classes that exist in the python standard library live in the collections module one of the simplest ones is the container class let' inspect it in the python interpreter to see what methods this class requiresfrom collections import container container __abstractmethods__ frozenset(['__contains__']sothe container class has exactly one abstract method that needs to be implemented__contains__ you can issue help(container __contains__to see what the function signature should look likehelp on method __contains__ in module _abcoll__contains__(selfxunbound _abcoll container method sowe see that __contains__ needs to take single argument unfortunatelythe help file doesn' tell us much about what that argument should bebut it' pretty obvious from the name of the abc and the single method it implements that this argument is the value the user is checking to see if the container holds this method is implemented by liststrand dict to indicate whether or not given value is in that data structure howeverwe can also define silly container that tells us whether given value is in the set of odd integersclass oddcontainerdef __contains__(selfx)if not isinstance(xintor not return false return true