object-oriented programming from abc import abcmetaabstractmethod need these definitions class sequence(metaclass=abcmeta) """our own version of collections sequence abstract base class "" @abstractmethod def len (self) """return the length of the sequence "" @abstractmethod def getitem (selfj) """return the element at index of the sequence "" def contains (selfval) """return true if val found in the sequencefalse otherwise "" for in range(len(self)) if self[ =valfound match return true return false def index(selfval) """return leftmost index at which val is found (or raise valueerror"" for in range(len(self)) if self[ =valleftmost match return never found match raise valueerrorvalue not in sequence def count(selfval) """return the number of elements equal to given value "" = for in range(len(self)) if self[ =valfound match + return code fragment an abstract base class akin to collections sequence this implementation relies on two advanced python techniques the first is that we declare the abcmeta class of the abc module as metaclass of our sequence class metaclass is different from superclassin that it provides template for the class definition itself specificallythe abcmeta declaration assures that the constructor for the class raises an error