... def __init__(self):class A:
<function A.__init__ at 0x0000026CFC5CCEE0>A.__init__
<bound method A.__init__ of <__main__.A object at 0x0000026CFC1BB400>>a = A()
a.__init__
The book PYTHON CRASH COURSE
I wonder how can I call `__init__` as?
|<slot wrapper '__init__' of 'object' objects>object.__init__
|<method-wrapper '__init__' of object object at 0x0...>object().__init__
```python
... def __init__(self):class A:
... pass
...
<function A.__init__ at 0x0000026CFC5CCEE0>A.__init__
<bound method A.__init__ of <__main__.A object at 0x0000026CFC1BB400>>a = A()
a.__init__
```
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!
```python
... def __init__(self):class A:
... pass
...
<function A.__init__ at 0x0000026CFC5CCEE0>A.__init__
<bound method A.__init__ of <__main__.A object at 0x0000026CFC1BB400>>a = A()
a.__init__
```
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!
--
https://mail.python.org/mailman/listinfo/python-list
```python
... def __init__(self):class A:
... pass
On many books and even the official documents, it seems that
many authors prefer to call `__init__` as a "method" rather
than a "function".
To me __init__ is a method, but that is implemented internally as
function associated to a class
```python
... def __init__(self):class A:
... pass
...
```
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...
<function A.__init__ at 0x0000026CFC5CCEE0>A.__init__
a = A()
a.__init__
<bound method A.__init__ of <__main__.A object at 0x0000026CFC1BB400>>
I wonder how can I call `__init__` as? Consider the output above.
Maybe both are OK?
Like all of the other __<name>__ methods you shouldn't ever need toThere is an exception:
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.
its both, depending on how you're getting it.Might can be more clear: its both, depending on how you're using/getting it.
A method in object-oriented programming (OOP) is a procedure associated with an object, and generally also a message. An object consists of state data and behavior; these compose an interface, which specifies how the object may be used. A method is abehavior of an object parametrized by a user.
Static methods are meant to be relevant to all the instances of a class rather than to any specific instance.This explanation might can "group" some functions back to "methods" :) However, let's still remember:
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 300 |
Nodes: | 16 (2 / 14) |
Uptime: | 74:52:37 |
Calls: | 6,715 |
Calls today: | 3 |
Files: | 12,246 |
Messages: | 5,357,385 |