Answer the question
In order to leave comments, you need to log in
How does __new__ work in Python 3?
Please explain how the __new__ method works in Python 3, preferably with examples. What should I write in return so that it returns an instance of my class. I was looking for solutions to my question, a lot for Python 2, the documentation is not clear, there are no examples. Help
Answer the question
In order to leave comments, you need to log in
__new__(cls, *args, **kwargs) - always a classmethod. Called to create an instance of the class, before calling __init__. A new instance is created by calling object.__new__(cls) (you can also use super() instead of explicitly specifying object). It should be returned by __new__.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question