sample = "This is a string" n = 3 # I want to iterate over every third element for i,x in enumerate(sample): if i % n == 0: print("do something with x "+x) else: print("do something else with x "+x)