Which of the following is a correct Python function definition using type annotations?

Options

  • A. def fun(float *a, int b):
  • B. def fun(a: float, b: str) -> int:
  • C. int fun(float a, str b):
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

B. def fun(a: float, b: str) -> int:

Detailed Explanation

Python uses type annotations in the form parameter: type and -> return_type. They are not automatically enforced at runtime.