supported in xwhile it would be easier to erase history entirelythis book is designed to support both and readers because __cmp__ may appear in code readers must reuse or maintainit' fair game in this book moreover__cmp__ was removed more abruptly than the __getslice__ method described earlierand so may endure longer if you use xthoughor care about running your code under in the futuredon' use __cmp__ anymoreuse the more specific comparison methods instead boolean tests__bool__ and __len__ the next set of methods is truly useful (yespun intended!as we've learnedevery object is inherently true or false in python when you code classesyou can define what this means for your objects by coding methods that give the true or false values of instances on request the names of these methods differ per python linethis section starts with the storythen shows ' equivalent as mentioned briefly earlierin boolean contextspython first tries __bool__ to obtain direct boolean valueif that method is missingpython tries __len__ to infer truth value from the object' length the first of these generally uses object state or other information to produce boolean result in xclass truthdef __bool__(self)return true truth(if xprint('yes!'yesclass truthdef __bool__(self)return false truth(bool(xfalse if this method is missingpython falls back on length because nonempty object is considered true ( nonzero length is taken to mean the object is trueand zero length means it is false)class truthdef __len__(self)return truth(if not xprint('no!'noif both methods are present python prefers __bool__ over __len__because it is more specificboolean tests__bool__ and __len__