String indexing: Random Access : String Index « String « Python






String indexing: Random Access

String indexing: Random Access
 
import random

word = "index"
print "The word is: ", word, "\n"

high = len(word)
low = -len(word)

for i in range(10):
    position = random.randrange(low, high)
    print "word[", position, "]\t", word[position]

           
         
  








Related examples in the same category

1.An index that is too large is replaced by the string size
2.Indices may be negative numbers, to start counting from the right. For example:
3.String indexing: from front or endString indexing: from front or end