Interview Prep/Python for DevOps/Language essentials & functions

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.

All Python for DevOps questions Roadmap: Python for automation

More on Language essentials & functions