Name the Slice
Name the Method
What would print?
What would the methods return?
Miscellaneous
100

word = "strawberry"

"b"

word[5]

100

This method returns a string with all capital letters.

.upper()

100

word = "guava",

print(word[1])

"u"

100

Given word = "grapes",

word.find("g")

0

100

What boolean value does this evaluate to:

"s" in "strawberry"

True

200

word = "strawberry"

"erry"

word[6: ] (or equivalent answer)

200

This method returns how many of a smaller string appears in a larger string.

.count()

200

print(len("lemon"))

5

200

Given word = "Pineapple",

word.replace("p", "z")

Pineazzle

200

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)

300

word = "strawberry"

"srwer"

word[ : : 2] (or equivalent answer)

300

This method gives the index of the last instance of a shorter string within a larger string.

.rfind()

300

word = "pear"

for x in word:

    print(x)

How many times will the for loop iterate?

4

300

Given word = "coconut",

word.replace("u", "o").count("o")

3

300

Spot the syntax mistake:

x = input("Enter a letter: ").lower

.lower() needs parentheses

400

word = "strawberry"

Two concatenated slices

"yaw"

word[9] + word[3:5]

400

This method returns -1 if a smaller string does not show up in a larger string.

.find() or .rfind()

400

word = "blackberry"

print(len(blackberry[2 : ])

8

400

Given word = "avocado",

word.replace("a", "c").rfind("a")

-1

400

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.

500

word = "strawberry"

"warts"

word[4: : -1] (or equivalent answer)

500

This method can sometimes be used to remove all instances of a smaller string within a larger string.

.replace()

500

See slide...

PeAcH

500

Given word = "watermelon",

word[5 : 9].upper().find("O")

3

500

Strings are immutable, which means that strings cannot be truly modified, only ________.

Replaced

M
e
n
u