Introduction
Iterating over strings lets you look at each letter one by one. This helps when you want to check or change parts of a word or sentence.
Jump into concepts and practice - no test required
for letter in string: # do something with letter
word = "hello" for letter in word: print(letter)
text = "Python" for char in text: print(char.upper())
name = "Anna" count_a = 0 for ch in name: if ch == 'a' or ch == 'A': count_a += 1 print(count_a)
sentence = "Hello World" for letter in sentence: if letter != ' ': print(letter)
for letter in "hello":
print(letter)text?for variable in string:.for char in text:
print(char) uses correct syntax. The other options use invalid syntax like 'to' instead of 'in', range() on a string, or non-existent .length attribute.word = "code"
result = ""
for ch in word:
result += ch.upper()
print(result)text = "hello"
for i in text:
print(text[i])sentence. Which code correctly does this?