len(instance)not instance def __add__(selfother)return stack(self stack other stackinstance instance def __mul__(selfreps)return stack(self stack repsinstance reps def __getitem__(selfoffset)return self stack[offsetsee also __iter__ instance[ ][ : ]infor def __getattr__(selfname)return getattr(self stacknameinstance sort()/reverse()now distinct instances are created by calling the stack class like function in most respectsthe stack class implements operations exactly like the stack module in example - but hereaccess to the stack is qualified by selfthe subject instance object each instance has its own stack attributewhich refers to the instance' own list furthermoreinstance stacks are created and initialized in the __init__ constructor methodnot when the module is first imported let' make couple of stacks to see how all this works in practicefrom stack import stack stack( push('spam' push( [stack:[ 'spam']make stack objectpush items __repr__ prints stack stack(two distinct stack objects push( they do not share content push( pop()xy ([stack:['spam']][stack:[ ]] stack(for in 'spam' push(cwhile zprint( pop()end=' [stack:['spam' ]for item in zprint(itemend='spam reverse( [stack:[ 'spam']third distinct stack object __len__ tests stack truth __add__ handles stack holds three different types __getitem__ does for __getattr__ delegates to list implementing stacks