There is no reason not to use:
>>> for char in "cdefg": ... print(char) c d e f g
Even if you are not a programmer, you can understand what the loop does, it is mostly English. It is also much cleaner, shorter, and the best thing is that it is 6 times faster than the chr(ord()) solution:
>>> import timeit >>> timeit.timeit("for i in 'abcdefg': x = i") 0.27417739599968627 >>> timeit.timeit("for i in range(ord('a'), ord('g') + 1): x = chr(i)") 1.7386019650002709
user2032433
source share