Why doc call `__init__` as a method rather than function?

Roel Schroeven roel at roelschroeven.net
Mon Sep 18 04:19:12 EDT 2023


Op 15/09/2023 om 15:05 schreef anthony.flury via Python-list:
> Like all of the other __<name>__ methods you shouldn't ever need to 
> call them directly : these are called dunder methods and represent 
> functions and features which are called by other operators.
>
> The only recommended way to call A.__init__ is to create an instance 
> of A : obj = A() - the __init__ method gets called automatically with 
> a newly created object.
There is an exception:

   super().__init__()

to call the base class's __init__ (normally from the derived class's 
__init__)

-- 
"Human beings, who are almost unique in having the ability to learn from the
experience of others, are also remarkable for their apparent disinclination
to do so."
         -- Douglas Adams



More information about the Python-list mailing list