ProtocolsDunder Methods (__str__, __repr__, __len__)
All courses

Make your objects feel native

Double-underscore methods hook into Python's data model. Implement __len__ for len(obj), __repr__ for developer-friendly debug output.

Quirk: __str__ is for users, __repr__ should be unambiguous. If you only implement one, make it __repr__.

Output
Press Run to execute your code.