__str__ method of a class is invoked
whenever an instance of that class must be converted to a
string. This happens, for instance, when you print an
instance with a
str() function on an instance.
def __str__ ( self ): '''Display self as a string. ''' return "%d/%d" % ( self.n, self.d )