Overload () operator in Python

Each Answer to this Q is separated by one/two green lines.

I am trying to learn currying in Python for my class and I have to overload the () operator for it. However, I do not understand how can I can go about overloading the () operator. Can you explain the logic behind overloading the parentheses? Should I overload first ( and then ) or can I do any of these? Also, is there special name for parentheses operator?

You can make an object callable by implementing the __call__ method:

class FunctionLike(object):
    def __call__(self, a):
        print("I got called with {!r}!".format(a))

fn = FunctionLike()
fn(10)

# --> I got called with 10!


The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .