create large number of objectsusing _slots_ can result in substantial reduction in memory use and execution time be aware that the use of _slots_ has tricky interaction with inheritance if class inherits from base class that uses _slots_ _it also needs to define _slots_ for storing its own attributes (even if it doesn' add anyto take advantage of the benefits _slots_ provides if you forget thisthe derived class will run slower and use even more memory than what would have been used if _slots_ had not been used on any of the classesthe use of _slots_ can also break code that expects instances to have an underlying _dict_ attribute although this often does not apply to user codeutility libraries and other tools for supporting objects may be programmed to look at _dict_ for debuggingserializing objectsand other operations finallythe presence of _slots_ has no effect on the invocation of methods such as _getattribute_ () _getattr_ ()and _setattr_ (should they be redefined in class howeverthe default behavior of these methods will take _slots_ into account in additionit should be stressed that it is not necessary to add method or property names to _slots_ _as they are stored in the classnot on per-instance basis operator overloading user-defined objects can be made to work with all of python' built-in operators by adding implementations of the special methods described in to class for exampleif you wanted to add new kind of number to pythonyou could define class in which special methods such as _add_ (were defined to make instances work with the standard mathematical operators the following example shows how this works by defining class that implements the complex numbers with some of the standard mathematical operators note because python already provides complex number typethis class is only provided for the purpose of illustration class complex(object)def _init_ (self,real,imag= )self real float(realself imag float(imagdef _repr_ (self)return "complex(% ,% )(self realself imagdef _str_ (self)return "(% +%gj)(self realself imagself other def _add_ (self,other)return complex(self real other realself imag other imagself other def _sub_ (self,other)return complex(self real other realself imag other imagin the examplethe _repr_ (method creates string that can be evaluated to recreate the object (that is"complex(real,imag)"this convention should be followed for all user-defined objects as applicable on the other handthe _str_ (method lib fl ff