>>> bob = "bob"
>>> range(0, len(bob))
[0, 1, 2]
>>> bob[0:2]
'bo'
>>> bob[0:3]
'bob'
Is there a convenient way to iterate over strings in python when I need the index number? If I make a for loop with range(0, len(astring)), it will only end up going up to the second-to-last character: I would instead have to write range(0, len(astring) + 1), which is kind of annoying. I can't do for c in astring because I am taking substrings. Suggestions?
lensuch that it returns the result oflenbut with 1 added to it.[x, y]vs[x, y)in mathematics, andx to yvsx until yin the scala core library. It's a more direct expression of your intention.