the iterator protocol the abstract base class iteratorin the collections abc moduledefines the iterator protocol in python as mentionedit must have __next__ method that the for loop (and other features that support iterationcan call to get new element from the sequence in additionevery iterator must also fulfill the iterable interface any class that provides an __iter__ method is iterablethat method must return an iterator instance that will cover all the elements in that class since an iterator is already looping over elementsits __iter__ function traditionally returns itself this might sound bit confusingso have look at the following examplebut note that this is very verbose way to solve this problem it clearly explains iteration and the two protocols in questionbut we'll be looking at several more readable ways to get this effect later in this class capitaliterabledef __init__(selfstring)self string string def __iter__(self)return capitaliterator(self stringclass capitaliteratordef __init__(selfstring)self words [ capitalize(for in string split()self index def __next__(self)if self index =len(self words)raise stopiteration(word self words[self indexself index + return word def __iter__(self)return self