the fraction objectmy_fdoes not know how to respond to this request to print the print function requires that the object convert itself into string so that the string can be written to the output the only choice my_f has is to show the actual reference that is stored in the variable (the address itselfthis is not what we want there are two ways we can solve this problem one is to define method called show that will allow the fraction object to print itself as string we can implement this method as shown in listing if we create fraction object as beforewe can ask it to show itselfin other wordsprint itself in the proper format unfortunatelythis does not work in general in order to make printing work properlywe need to tell the fraction class how to convert itself into string this is what the print function needs in order to do its job listing show function def show(self)print(self num"/"self denmy_f fraction( my_f show( print(my_fin pythonall classes have set of standard methods that are provided but may not work properly one of these__str__is the method to convert an object into string the default implementation for this method is to return the instance address string as we have already seen what we need to do is provide "betterimplementation for this method we will say that this implementation overrides the previous oneor that it redefines the method' behavior to do thiswe simply define method with the name __str__ and give it new implementation as shown in listing this definition does not need any other information except the special parameter self in turnthe method will build string representation by converting each piece of internal state data to string and then placing character in between the strings using string concatenation the resulting string will be returned any time fraction object is asked to convert itself to string notice the various ways that this function is used listing standard method def __str__ (self)return str(self num"/str(self denmy_f fraction( print(my_f / print(" ate"my_f"of the pizza" ate / of the pizza my_f __str__( introduction