partials

Run Settings
LanguagePython
Language Version
Run Command
from functools import partial def my_func(a,b,c): print(a,b,c) my_func(10,20,30) def f(x,y): return my_func(10,x,y) f(20,30) g=partial(my_func,10) g(20,30) def func1(a,b, *args, k1,k2, **kwargs): print(a,b,args,k1,k2,kwargs) func1(10,20,30,40,k1='a',k2='b', k3=1000, k4=2000) def g1(x,*vars, kw, **kwvars): return func1(10,x,*vars,k1='a',k2=kw,**kwvars) g1(10,100,200,kw='a',k3="1000",k4="2000") # for partial g2=partial(func1,10,k1='a') g2(20,100,200,k2='b',k3='1000',k4='2000') def power(base, exponent): return base ** exponent square = partial(power, exponent=2) cube = partial(power, exponent=3) cube(base=3) cube(3) # partial creating, the first arg is hard coded and, not going to change after # globals return dictionary print(globals()) print(globals()["g2"](3)) # I have a globals, I have a locals() # let see what's inside the partial module, by calling internal function call print(partial.__dict__) # or, we call the internal by dir() another internal function call print(dir(partial))
Editor Settings
Theme
Key bindings
Full width
Lines