print(stack item( )end=' stack class perhaps the biggest drawback of the module-based stack is that it supports only single stack object all clients of the stack module effectively share the same stack sometimes we want this featurea stack can serve as shared-memory object for multiple modules but to implement true stack datatype that can generate independent objectswe need to use classes to illustratelet' define full-featured stack class the stack class shown in example - defines new datatype with variety of behaviors like the modulethe class uses python list to hold stacked objects but this timeeach instance gets its own list the class defines both "realmethods and specially named methods that implement common type operations comments in the code describe special methods example - pp \dstruct\basic\stack py " multi-instance stack classclass error(exception)pass class stackdef __init__(selfstart=[])self stack [for in startself push(xself reverse(def push(selfobj)self stack [objself stack when importedlocal exception self is the instance object start is any sequencestack undo push' order reversal methodslike module self top is front of list def pop(self)if not self stackraise error('underflow'top*self stack self stack return top def top(self)if not self stackraise error('underflow'return self stack[ def empty(self)return not self stack instance empty(overloads def __repr__(self)return '[stack:% ]self stack printrepr()def __eq__(selfother)return self stack =other stack '==''!='def __len__(self) data structures