class Iterator: def __init__(self, origin_list): self._ref = origin_list self.n = -1 def __next__(self): if self.n < len(self._ref) - 1: self.n += 1 return self._ref[self.n] raise StopIteration() class A: def __init__(self): self.a = [1, 2, 3, 4] def __iter__(self): return Iterator(self.a) a = A() for el in a: print(el)