Python: Strings Flashcards

1
Q

What will the following code print to terminal?

def print_some_characters(word):
for i in range(len(word)):
if i % 2 == 0:
print(word[i])

print_some_characters(“watermelon”)

A

w
t
r
e
o

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What character will be selected from the string cool_fruit = “watermelon” using the code cool_fruit[len(cool_fruit) - 2]?

A

“o”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which of the following expressions is False?

”s” in “watermelon”

“cherry” in “cherry”

“cran” in “cranberry”

“a” in “banana”

A

”s” in “watermelon”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Consider the following function. What would it print to the terminal?

def tell_me_about_icecream(favorite_icecream):
response = “My favorite icecream is” + favorite_icecream + “.”
print(response)

tell_me_about_icecream(“chocolate”)

A

My favorite icecream ischocolate.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Given the string least_favorite_fruit = “cantaloupe”, what piece of code would create a string that was equal to “lou” using slice?

A

least_favorite_fruit[5:8]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What code would select the letter “p” from the string good_fruit = “Raspberry”?

A

good_fruit[3]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly