herethe differentiate method will change the polynomial itselfsince this is the behavior indicated by the way the function was used above we have also added separate function derivative that does not change the polynomial butinsteadreturns its derivative as new polynomial object finallylet us implement the __str__ method for printing the polynomial in human-readable form this method should return string representation close to the way we write polynomial in mathematicsbut achieving this can be surprisingly complicated the following implementation does reasonably good jobclass polynomialdef __str__(self) 'for in range( len(self coeff))if self coeff[ ! + {self coeff[ ]: }* ^{ : }fix layout (many special cases) replace('-''' replace( *'' replace(' ^ '' ' replace(' ^ '' 'if [ : ='remove initial [ :if [ : ='fix spaces for initial '- [ :return for all these special methodsas well as special methods in generalit is important to be aware that their contents and behavior are entirely up to the programmer the only special thing about special methods is their namewhich ensures that they are automatically called by certain operations what they actually do and what they return are decided by the programmer writing the class if we want to write an __add__ method that returns nothingor returns something completely different from sumwe are free to do so howeverit isof coursea good habit for the __add__(selfotherto implement something that seems like meaningful result of self other open access dieses kapitel wird unter der creative commons namensnennung international lizenz (in jeglichem medium und format erlaubtsofern sie den/die ursprunglichen autor(enund die quelle ordnungsgemass nenneneinen link zur creative commons lizenz beifugen und angebenob anderungen vorgenommen wurden die in diesem kapitel enthaltenen bilder und sonstiges drittmaterial unterliegen ebenfalls der genannten creative commons lizenzsofern sich aus der abbildungslegende nichts anderes ergibt sofern das betreffende material nicht unter der genannten creative commons lizenz steht und die betreffende handlung nicht nach gesetzlichen vorschriften erlaubt istist fur die oben aufgefuhrten weiterverwendungen des materials die einwilligung des jeweiligen rechteinhabers einzuholen