__sizeof__
Dunder MethodPython 2.0+Advanced
Returns the memory size of the object in bytes
Quick Info
- Documentation
- Official Docs
- Python Version
- 2.0+
Learn by Difficulty
Quick Example
python
class Example: def __sizeof__(self): return "Example __sizeof__" obj = Example() print(obj)
__sizeof__ returns the memory size of the object in bytes. Implementing it lets you customize how Python interacts with your objects.
Try in PlaygroundTags
oopmagic-methodprotocolcore