word = "strawberry"
"b"
word[5]
This method returns a string with all capital letters.
.upper()
word = "guava",
print(word[1])
"u"
Given word = "grapes",
word.find("g")
0
What boolean value does this evaluate to:
"s" in "strawberry"
True
word = "strawberry"
"erry"
word[6: ] (or equivalent answer)
This method returns how many of a smaller string appears in a larger string.
.count()
print(len("lemon"))
5
Given word = "Pineapple",
word.replace("p", "z")
Pineazzle
Use context clues to fill in the if statement:
word = ("Enter a word: ")
if ________________:
print("That's not one word!")
" " in word (or equivalent answer)
word = "strawberry"
"srwer"word[ : : 2] (or equivalent answer)
This method gives the index of the last instance of a shorter string within a larger string.
.rfind()
word = "pear"
for x in word:
print(x)
How many times will the for loop iterate?
4
Given word = "coconut",
word.replace("u", "o").count("o")
3
Spot the syntax mistake:
x = input("Enter a letter: ").lower
.lower() needs parentheses
word = "strawberry"
Two concatenated slices
"yaw"
word[9] + word[3:5]
This method returns -1 if a smaller string does not show up in a larger string.
.find() or .rfind()
word = "blackberry"
print(len(blackberry[2 : ])
8
Given word = "avocado",
word.replace("a", "c").rfind("a")
-1
What is wrong with the following code, intended to print "plum"?
word = "PLUM"
word.lower()
print(word)
.lower() doesn't change a variable. word doesn't actually change because it was never replaced.
word = "strawberry"
"warts"
word[4: : -1] (or equivalent answer)
This method can sometimes be used to remove all instances of a smaller string within a larger string.
.replace()
See slide...
PeAcH
Given word = "watermelon",
word[5 : 9].upper().find("O")
3
Strings are immutable, which means that strings cannot be truly modified, only ________.
Replaced