Check your understanding of the previous reading: reading function documentation, the parts of a method call, and computing string method results by hand.

Question 1

True or False: The input function returns a string.

Select one answer, then check.

  • Correct. Whatever the user types, input always hands it back as a string — even if they typed digits.
  • Not quite. input always returns the user's response as a string, which is why you often need to convert it with int or float afterwards.

Question 2

True or False: The print function returns a string.

Select one answer, then check.

  • Not quite. print writes text to the console as a side effect, but the value it returns is None, not a string.
  • Correct. print returns None. Writing to the console is a side effect, not its return value.

Question 3

According to the linked documentation, what type of value does the string.count() function return?

Show worked solution

count() counts how many times a substring occurs, so it returns an integer (a whole number).

Question 4

According to the linked documentation, how many parameters does the string.split() function take?

Show worked solution

The linked documentation page lists exactly one parameter for split(): separator, the string to split on. That page's syntax line is a_string.split(separator). sep and maxsplit are CPython's actual parameter names, but they don't appear on the linked page, and maxsplit doesn't appear anywhere else in this course either. The answer, grounded in what the linked page documents, is one parameter.

Question 5

What is the result of each of the following expressions involving a method call?

"To be Or not to be, that is the question.".count("o")

Result:

"You should remember how to use subscripts"[5:10].count("o")

Result:

"Where's waldo?".find("w")

Result:

"To be or not to be, that is the question.".upper().count("TO")

Result:

"eeeeee".replace("ee", "e").count("e")

Result:

Word bank — not all values are used

Question 6

Given the method call below, identify each component.
"Open the pod bay doors, Hal!".replace("Open", "Close")
"Open the pod bay doors, Hal!"
replace
"Open" (first)
"Close" (second)
(

Question 7

Match each definition to the term it describes. Three terms in the list are not used.
DefinitionTerm
The names given to the values that will be passed into a function.
The curved symbols that go after a function name to ensure that it is called.
A reusable chunk of code that can be called using its name and parentheses.
The values passed into a function.
The extra information about a function supplied to help other programmers understand how to use the function.
The act of using a function via its name and parentheses.