A fun thing about "partial"

If you use named arguments, partial returns a function with a signature with those arguments set as if they were the defaults.

However, if you use positional arguments, partial returns a function with all but the arguments set positionally.

def my_func(start, end, pos):
    pass

f = partial(my_func, 0, 1) # => f(pos)
f = partial(my_func, start=0, end=1) #=> f(start=0, end=1, pos)

It was bothering me when in Lesson 9, Jeremy showed how to use partial in a way that made the arguments look like they had disappeared.

2 Likes

def my_func(start, end, pos): print(start,end,pos)

f1 = partial(my_func,0,1)
f2 = partial(my_func,start=0,end=1)
f3 = partial(my_func,end=1,pos=2)

f1(3) => returns 012
f2(3) => returns error , multiple values for argument ‘start’
f3(0) => returns 012

Looks like it has a problem with the first positional arguement

f2(pos=3)