def _range(start, stop): assert start < stop def inside_gen(): nonlocal start while start < stop: print("Going to return: ", start) yield start start += 1 print("here") return inside_gen() # for el in _range(0, 10): # print(el)