Write a for loop to print every character in the string a_str
.
p
p
l
e
p
p
l
e
l
a
s
k
a
l
a
s
k
a
r
e
a
k
f
a
s
t
t
a
c
o
s
r
e
a
k
f
a
s
t
t
a
c
o
s
r
e
a
t
j
o
b
!
r
e
a
t
j
o
b
!
Instructor solution
4.2 For Loops - Lesson
For loops with strings
For loops can be used to iterate through characters in a string, like so:
a_str = "banana"
for c in a_str: # c is short for character, but it is just a variable name
print(c)
Practice!
Think you've got it?
Which of the following while loops prints every character in a string a_str
?
- A.
i = 0 while i < len(a_str): print(a_str[i])
- B.
i = 1 while i < len(a_str): print(a_str[i]) i += 1
- C.
i = 0 while i <= len(a_str): print(a_str[i]) i += 1
- D.
i = 0 while i < len(a_str): print(a_str) i += 1
- E.
i = 0 while i < len(a_str): print(a_str[i]) i += 1
You may exit out of this review and return later without penalty.