extending built-in types besides implementing new kinds of objectsclasses are sometimes used to extend the functionality of python' built-in types to support more exotic data structures for instanceto add queue insert and delete methods to listsyou can code classes that wrap (embeda list object and export insert and delete methods that process the list speciallylike the delegation technique we studied in as of python you can also use inheritance to specialize built-in types the next two sections show both techniques in action extending types by embedding do you remember those set functions we wrote in and here' what they look like brought back to life as python class the following example (the file setwrapper pyimplements new set object type by moving some of the set functions to methods and adding some basic operator overloading for the most partthis class just wraps python list with extra set operations but because it' classit also supports multiple instances and customization by inheritance in subclasses unlike our earlier functionsusing classes here allows us to make multiple self-contained set objects with preset data and behaviorrather than passing lists into functions manuallyclass setdef __init__(selfvalue [])self data [self concat(valueconstructor manages list def intersect(selfother)res [for in self dataif in otherres append(xreturn set(resother is any sequence self is the subject def union(selfother)res self data[:for in otherif not in resres append(xreturn set(resother is any sequence copy of my list add items in other def concat(selfvalue)for in valueif not in self dataself data append(xvaluelistset removes duplicates pick common items return new set def __len__(self)return len(self datadef __getitem__(selfkey)return self data[keydef __and__(selfother)return self intersect(otherdef __or__(selfother)return self union(other advanced class topics len(self)if self self[ ]self[ :jself other self other