Range with chars or strings in Python arrays -
i pretty new python coming java, c, , haskell environment, wondering if there exist similar following strings , not numbers, have:
for in range(5,11) print "index : %d" %i and result be: 5, 6, 7, 8, 9, 10 (each in new line of course). so, want have same strings, like:
for c in range("a","e") print "alphabet : %s" %c i curious , have tried many things both strings , chars not obtain result want. in advance.
strings iterable in python, can do:
for c in 'abcde': print 'alphabet:', c alphabet: alphabet: b alphabet: c alphabet: d alphabet: e if want alternative explicit range, there's (rather ugly):
for c in range(ord('a'), ord('e')+1): print 'alphabet:', chr(c) alphabet: alphabet: b alphabet: c alphabet: d alphabet: e range not take strings arguments in python, have convert characters ascii equivalents , again.
Comments
Post a Comment