__new__
Dunder MethodPython 2.0+Expert
Creates and returns a new instance before __init__ is called
Quick Info
- Documentation
- Official Docs
- Python Version
- 2.0+
Learn by Difficulty
Quick Example
python
class Example: def __new__(self): return "Example __new__" obj = Example() print(obj)
__new__ creates and returns a new instance before __init__ is called. Implementing it lets you customize how Python interacts with your objects.
Try in PlaygroundTags
oopmagic-methodprotocolcore