HomepageTeaching PageResearch PageResources Page

Homework: String Traversal

Read section 8.3 in the book and do the examples.

You'll want to become familiar with both traversals that use indices and those that don't. You can write a for-loop version that uses indices by using the range function. The following code is a step inbetween the first and second code examples in 8.3:

for index in range(len(fruit)):
    letter = fruit[index]
    print(letter)
        

It's common to use i instead of the whole word index. So we could rewrite this like:

for i in range(len(fruit)):
    letter = fruit[i]
    print(letter)