The first is used to initialise newly created object, and receives arguments used to do that:
class Foo:
def __init__(self, a, b, c):
# ...
x = Foo(1, 2, 3) # __init__
The second implements function call operator.
class Foo:
def __call__(self, a, b, c):
# ...
x = Foo()
x(1, 2, 3) # __call__
Related Contents:
- Why do Python classes inherit object?
- How do I call a parent class’s method from a child class in Python?
- What is the purpose of the word ‘self’?
- Static class variables and methods in Python
- Understanding Python super() with __init__() methods [duplicate]
- What is the difference between old style and new style classes in Python?
- How to print instances of a class using print()?
- Spawning multiple instances of the same object concurrently in python
- Python function overloading
- Saving and loading multiple objects in pickle file?
- difference between variables inside and outside of __init__()
- How can I create a copy of an object in Python?
- Explaining the ‘self’ variable to a beginner [duplicate]
- Getting an instance name inside class __init__() [duplicate]
- Attaching a decorator to all functions within a class
- Private members in Python
- How do I access Class member variables in Python?
- What is the `self` parameter in class methods?
- How can I create an object and add attributes to it?
- What is the purpose of python’s inner classes?
- difference between variables inside and outside of __init__() (class and instance attributes)
- List all base classes in a hierarchy of given class?
- Does Python have class prototypes (or forward declarations)?
- What is the purpose of the `self` parameter? Why is it needed?
- Prevent creating new attributes outside __init__
- Difference between ‘cls’ and ‘self’ in Python classes?
- Why is `object` an instance of `type` and `type` an instance of `object`?
- How do I set and access attributes of a class? [duplicate]
- How do I correctly setup and teardown for my pytest class with tests?
- Python: how to “kill” a class instance/object?
- How to implement a binary search tree in Python?
- Getting container/parent object from within python
- How to avoid having class data shared among instances?
- What are metaclasses in Python?
- How to access object attribute given string corresponding to name of that attribute
- What does ‘super’ do in Python? – difference between super().__init__() and explicit superclass __init__()
- What is a mixin and why is it useful?
- Does Python have “private” variables in classes?
- What is the __del__ method and how do I call it?
- Variable scopes in Python classes
- Why is the id of a Python class not unique when called quickly?
- What is a clean “pythonic” way to implement multiple constructors?
- How would I access variables from one class to another?
- Referring to the null object in Python
- Iterate over object attributes in python [duplicate]
- Possibilities for Python classes organized across files? [closed]
- How do I save and restore multiple variables in python?
- What is the advantage of using static methods?
- Dictionary vs Object – which is more efficient and why?
- Tkinter example code for multiple windows, why won’t buttons load correctly?