Home > Back-end >  Are there dunder methods for python functions?
Are there dunder methods for python functions?

Time:03-29

I'm just wondering are there dunder methods for python functions, to achieve something like this...

def f():
  ...

def g():
  ...

h = f   g

h()

CodePudding user response:

you could do something like this( i don't advise you to do so), but it can get very fast very nasty :

def f():
    return 1

def g():
    return 2

class hc(object):
    def __call__( self, f, g):
            return f()   g()

h = hc()
print(h(f,g))

3

Good luck :)

  • Related