Python·100 questions

What are dunder methods (__str__, __repr__, __iter__)?

Answer
These are object behavior protocols.
__repr__ — for developers, __str__ — for users.
__len__ makes the object compatible with len().
__iter__/__next__ — iterator.
__enter__/__exit__ — context manager.
Was this answer helpful?

More questions in this topic

Related questions from other topics