similar to lenreversed calls the __reversed__(function on the class for the parameter if that method does not existreversed builds the reversed sequence itself using calls to __len__ and __getitem__which are used to define sequence we only need to override __reversed__ if we want to somehow customize or optimize the processnormal_list=[ , , , , class customsequence()def __len__(self)return def __getitem__(selfindex)return " { }format(indexclass funkybackwards()def __reversed__(self)return "backwards!for seq in normal_listcustomsequence()funkybackwards()print("\ {}format(seq __class__ __name__)end=""for item in reversed(seq)print(itemend=""the for loops at the end print the reversed versions of normal listand instances of the two custom sequences the output shows that reversed works on all three of thembut has very different results when we define __reversed__ ourselveslist customsequencex funkybackwardsbackwards!when we reverse customsequencethe __getitem__ method is called for each itemwhich just inserts an before the index for funkybackwardsthe __reversed__ method returns stringeach character of which is output individually in the for loop the preceding two classes aren' very good sequences as they don' define proper version of __iter__so forward for loop over them will never end