What are dunder methods? Name the ones you actually use.
IntermediateConceptLanguage essentials & functions
Answer
Double-underscore methods hook into language syntax. The useful ones in tooling:
__init__,__repr__(debug output; dataclasses generate it)__eq__,__hash__(dedupe findings in a set)__enter__,__exit__(context managers)__iter__,__len__,__contains__(make an inventory iterable)__call__(callable objects)__str__(human output)
Implementing __repr__ alone pays for itself the first time you read a log line.
More on Language essentials & functions
Why is Python the default scripting language in so many DevOps teams, and where would you not use it?BeginnerWhat is the difference between mutable and immutable types? Give examples.BeginnerWhat does assignment do in Python, and how do shallow and deep copies differ?BeginnerExplain the mutable default argument bug and how to fix it.IntermediateWhat is the difference between `==` and `is`?BeginnerWhat values are "falsy" in Python, and why does it matter in scripts?Beginner