What is the output of the following code? from typing import Protocol class Drawable(Protocol): def draw(self) -> None: … class Circle: def draw(self) -> None: print(‘circle’) def render(shape: Drawable) -> None: shape.draw() render(Circle())

Python Professional Hard

Python Professional — Hard

What is the output of the following code? from typing import Protocol class Drawable(Protocol): def draw(self) -> None: … class Circle: def draw(self) -> None: print(‘circle’) def render(shape: Drawable) -> None: shape.draw() render(Circle())

Key points

  • The Circle class implements the draw method required by the Drawable protocol
  • The render function calls the draw method of the Circle class
  • The output of the code is determined by the implementation of the draw method in the Circle class

Ready to go further?

Related questions