Python: Strings Flashcards
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”)
w
t
r
e
o
What character will be selected from the string cool_fruit = “watermelon” using the code cool_fruit[len(cool_fruit) - 2]?
“o”
Which of the following expressions is False?
”s” in “watermelon”
“cherry” in “cherry”
“cran” in “cranberry”
“a” in “banana”
”s” in “watermelon”
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”)
My favorite icecream ischocolate.
Given the string least_favorite_fruit = “cantaloupe”, what piece of code would create a string that was equal to “lou” using slice?
least_favorite_fruit[5:8]
What code would select the letter “p” from the string good_fruit = “Raspberry”?
good_fruit[3]