4.6. Strings and
Since a string is simply a sequence of characters, the
for loop iterates over each character
automatically. (As always, try to predict what the output will be from this code before you run it.)
The loop variable
achar is automatically assigned each character in the string “Go Spot Go” one at a time.
We will refer to this type of sequence iteration as iteration by item. Note that the for loop
processes the characters in a string or items in a sequence one at a time from left to right.
Check your understanding