__format__
Dunder MethodPython 2.0+Intermediate
Called by format() and f-strings for custom formatting
Quick Info
- Documentation
- Official Docs
- Python Version
- 2.0+
Learn by Difficulty
Quick Example
python
class Example: def __format__(self): return "Example __format__" obj = Example() print(obj)
__format__ called by format() and f-strings for custom formatting. Implementing it lets you customize how Python interacts with your objects.
Try in PlaygroundTags
oopmagic-methodprotocolcore