i know the for loop:
for i range(2, 6):
print i
gives this output:
2
3
4
5
can i also do this somehow with letters? for example:
# an example for what i'm looking for
for i in range(c, h):
print i
c
d
f
g
I think it's nicer to add 1
to ord('g')
than using ord('h')
for code in range(ord('c'), ord('g') + 1):
print chr(code)
because what if you want to go to 'z', you need to know what follows 'z' . I bet you can type + 1
faster than you can look it up.
for i in 'cdefg':
...
for i in (chr(x) for x in range(ord('c'), ord('h'))):
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With