__missing__

Dunder MethodPython 2.0+Advanced

Called by dict subclasses when a key is not found

Quick Info

Documentation
Official Docs
Python Version
2.0+

Learn by Difficulty

Quick Example

python
class Example:
    def __missing__(self):
        return "Example __missing__"

obj = Example()
print(obj)

__missing__ called by dict subclasses when a key is not found. Implementing it lets you customize how Python interacts with your objects.

Try in Playground

Tags

oopmagic-methodprotocolcore