Learn
String manipulation is useful in for
loops if you want to modify some content in a string.
word = "Marble" for char in word: print char,
The example above iterates through each character in word
and, in the end, prints out M a r b l e
.
The ,
character after our print
statement means that our next print
statement keeps printing on the same line.
Instructions
1.
Let’s filter out the letter "A"
from our string.
- Do the following
for
eachchar
acter in thephrase
. - If
char
is an"A"
orchar
is an"a"
,print "X",
instead ofchar
. Make sure to include the trailing comma. - Otherwise (
else:
), pleaseprint char,
with the trailing comma.
Take this course for free
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.