0

Can I create a python function that is a subset of a different function, meaning I specify some, but not all of the parameters?

For example, here is some incorrect code illustrating what I'm looking for:

def foo(x, a, b):       # generic function
    return a * x + b

bar = foo(a=1., b=2.)   # create some specific functions
baz = foo(a=6., b=9.)   # that specify some of the parameters

bar(x=1)                # returns 3, can be used without tracking a,b
baz(x=1)                # returns 15

I'm nearly certain this is possible (the syntax is obviously wrong), but I can't remember the terminology to google it. Is it possible? What is the terminology and syntax for it?

martineau
  • 119,623
  • 25
  • 170
  • 301
ericksonla
  • 1,247
  • 3
  • 18
  • 34

0 Answers0