I currently use:
for i in range(1,10):print i
Which prints the digits 1 to 9. But I want to add a-z to the mix. How can I combine them?
I currently use:
for i in range(1,10):print i
Which prints the digits 1 to 9. But I want to add a-z to the mix. How can I combine them?
Rather than create a range, loop over a string, to get individual characters:
import stringfor character in string.ascii_lowercase + string.digits[1:]:print character
This uses the string
module to grab pre-defined strings of ASCII lowercase letters and digits.
The string.digits[1:]
slice removes the '0'
character to leave just the digits '1'
through to '9'
.