Embercode
✕
Functions and ScopeQuick quiz

Generic functions in Python

7 questions. Covers Generic functions in Python.

Questions 1 to 5 of 7

  1. 1. What does this program print? ``python def larger_of(a, b): if a >= b: return a return b print(larger_of(3, 7), larger_of("pear", "apple")) ``
  2. 2. Which type hint tells a type checker (a tool such as mypy that reads code without running it) that T must be str or a subclass of str?
  3. 3. Is this an error when the program runs? ``python x: list[int] = ["a", "b"] print(x) ``
  4. 4. How do you make a list of three empty slots in Python?
  5. 5. Which special method name does Python call for a < b on a class you wrote? Write the name, with the underscores.

    Type your answer.

5 question(s) left on this page.

Typed answers ignore extra spaces and, for most questions, capital letters.