types and objects if string expression cannot be createdthe convention is for _repr_ (to return string of the form as shown heref open("foo" repr(fa "the _str_ (method is called by the built-in str(function and by functions related to printing it differs from _repr_ (in that the string it returns can be more concise and informative to the user if this method is undefinedthe _repr_ (method is invoked the _format_ (method is called by the format(function or the format(method of strings the format_spec argument is string containing the format specification this string is the same as the format_spec argument to format(for exampleformat( ,"spec"" is { :spec}format(xcalls _format_ ("spec"calls _format_ ("spec"the syntax of the format specification is arbitrary and can be customized on an objectby-object basis howevera standard syntax is described in object comparison and ordering table shows methods that can be used to perform simple tests on an object the _bool_ (method is used for truth-value testing and should return true or false if undefinedthe _len_ (method is fallback that is invoked to determine truth the _hash_ (method is defined on objects that want to work as keys in dictionary the value returned is an integer that should be identical for two objects that compare as equal furthermoremutable objects should not define this methodany changes to an object will alter the hash value and make it impossible to locate an object on subsequent dictionary lookups table special methods for object testing and hashing method description _bool_ (self_ _hash_ (selfreturns false or true for truth-value testing computes an integer hash index objects can implement one or more of the relational operators (===!=each of these methods takes two arguments and is allowed to return any kind of objectincluding boolean valuea listor any other python type for instancea numerical package might use this to perform an element-wise comparison of two matricesreturning matrix with the results if comparison can' be madethese functions may also raise an exception table shows the special methods for comparison operators table methods for comparisons method result _lt_ (self,other_ _le_ (self,other_ _gt_ (self,other_ _ge_ (self,otherself other self <other self other self >other lib fl ff