__bytes__
Dunder MethodPython 2.0+Advanced
Called by bytes(); returns a bytes representation
Quick Info
- Documentation
- Official Docs
- Python Version
- 2.0+
Learn by Difficulty
Quick Example
python
class Example: def __bytes__(self): return "Example __bytes__" obj = Example() print(obj)
__bytes__ called by bytes(); returns a bytes representation. Implementing it lets you customize how Python interacts with your objects.
Try in PlaygroundTags
oopmagic-methodprotocolcore