scan can be active at any point in time ( nested loops won' work)because each iteration attempt resets the scan cursor to the front now that you know about yield in iteration methodsyou should be able to tell that the following is equivalent but allows multiple active scans--and judge for yourself whether its more implicit nature is worth the nested-scan support and six lines shaved (this is in file contains_yield py)class itersdef __init__(selfvalue)self data value def __getitem__(selfi)print('get[% ]:iend=''return self data[ifallback for iteration also for indexslice def __iter__(self)print('iter=next:'end=''for in self datayield print('next:'end=''preferred for iteration allows multiple active iterators no __next__ to alias to next def __contains__(selfx)print('contains'end=''return in self data preferred for 'inon both python and xwhen either version of this file runs its output is as follows --the specific __contains__ intercepts membershipthe general __iter__ catches other iteration contexts such that __next__ (whether explicitly coded or implied by yieldis called repeatedlyand __getitem__ is never calledcontainstrue iter=next: next: next: next: next: nextiter=next:next:next:next:next:next:[ iter=next:next:next:next:next:next:[' '' '' '' '' 'iter=next: next: next: next: next: nextwatch what happens to this code' output if we comment out its __contains__ methodthough--membership is now routed to the general __iter__ insteaditer=next:next:next:true iter=next: next: next: next: next: nextiter=next:next:next:next:next:next:[ iter=next:next:next:next:next:next:[' '' '' '' '' 'iter=next: next: next: next: next: nextand finallyhere is the output if both __contains__ and __iter__ are commented out --the indexing __getitem__ fallback is called with successively higher indexes until it raises indexerrorfor membership and other iteration contextsget[ ]:get[ ]:get[ ]:true get[ ]: get[ ]: get[ ]: get[ ]: get[ ]: get[ ]get[ ]:get[ ]:get[ ]:get[ ]:get[ ]:get[ ]:[ get[ ]:get[ ]:get[ ]:get[ ]:get[ ]:get[ ]:[' '' '' '' ',' 'get[ ]: get[ ]: get[ ]: get[ ]: get[ ]: get[ ] operator overloading