What is the purpose of a callable object? What problems do they solve?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
They take parameters and return a result depending on those parameters.
A callable is just an abstract form of a function resp an interface that defines that an object acts like a function (i.e. accepts parameters).
As functions are first class objects, it is obvious that functions are callable objects. If you are talking about the
__call__method, this is just one of the many special methods with which you can overload the behavior of custom objects, e.g. for arithmetic operations or also defining what happens if you call an object.One idea why to use such is to have some kind of factory object that itself creates other objects.