Why doc call `__init__` as a method rather than function?
scruel tao
scruelt at hotmail.com
Fri Sep 15 06:49:10 EDT 2023
```python
>>> class A:
... def __init__(self):
... pass
...
>>> A.__init__
<function A.__init__ at 0x0000026CFC5CCEE0>
>>> a = A()
>>> a.__init__
<bound method A.__init__ of <__main__.A object at 0x0000026CFC1BB400>>
```
On many books and even the official documents, it seems that many authors prefer to call `__init__` as a "method" rather than a "function".
The book PYTHON CRASH COURSE mentioned that "A function that’s part of a class is a method.", however, ` A.__init__` tells that `__init__` is a function...
I wonder how can I call `__init__` as? Consider the output above.
Maybe both are OK? If you prefer or think that we must use one of the two, please explain the why, I really want to know, thanks!
More information about the Python-list
mailing list