Python named keyword by variable -
i'm new python , i'm trying figure out if can pass named keywords string without calling them explicitly. here example:
def test(height, weight): print("h=" + str(height)) print("w=" + str(weight)) test(weight=1, height=2) # output = "weight" b = "height" test(a=1, b=2) # same output
is possibile? thanks!
use dict
.
kwargs = {a: 1, b: 2} test(**kwargs)
Comments
Post a Comment