I'm trying to figure out kwargs and do some simple string formatting.
def basic_human(first_name='Jeff', age=42):
return f"My name is {first_name}, and my age is {age}"
def starwars_fan(movie='A new hope', jedi='Young Obi Wan', **kwargs):
human_string = basic_human(kwargs)
return f"{human_string}. My favorite movie is {movie}, and my favorite Jedi is {jedi}."
print(basic_human(first_name='Mr. Baby', age=0.8))
print(starwars_fan(person_name='Chris', jedi='Kit Fisto'))
In the first case, things work fine:
My name is Mr. Baby, and my age is 0.8
In the second case, the person_name parameter comes in as a dict and I'm not sure why:
My name is {'first_name': 'Chris'}, and my age is 42. My favorite movie is A new hope, and my favorite Jedi is Kit Fisto.
Is there a way to make this work without explicitly overriding each of the "basic human" params?
def basic_human(first_name='Jeff', age=42, other_params=None):
if other_params:
if 'first_name' in other_params:
first_name = other_params['first_name']...
return f"My name is {first_name}, and my age is {age}"