PythiloLesson 13 of 30 · progress kept in this browser

Protocols and duck typing

Python does not ask what class an object is. It asks whether the object has the attribute you are about to use. That is duck typing: if it has .read(), it can be read.

def shout(thing):
    return thing.text().upper()

Any object with a text method works, and no shared base class is needed.

Your task

Write a runtime-checkable protocol Renderer with render(self) -> str. Write classes Text(value) rendering the value and Bold(value) rendering **value**, neither inheriting from Renderer. Write render_all(items) joining the rendered items with newlines.