from itertools import islice for i in islice(range(20), 1, 5): # islice(items, start, stop, step) print(i) # Output: # 1 2 3 4