build a string based on user's input python I need to write a function to build a string based on user input.
when user provide one type group of input: "tab" and link variable the string should be tab_link: xxxx.
when user provide one type group of input: "subtab" and link variable the string should be subtab_link: subtabxxxxx.

the logic is pretty much like following function. but do I have better way to do it then using if, else? because lets say if I have multiple group, does it mean I need to have more if, elif, elif to identify different group input and match the string?

subtab = {'subtab1': 1, 'subtab2': 2, 'subtab3': 3}
_dir = {'tab': 'tab_link:{}', 'subtab': 'subtab_link:{}'}

def func(**kwargs):
    if kwargs['_type'] == 'tab':
        print(_dir[kwargs['_type']].format(kwargs['_link']))
    else:
        print(_dir[kwargs['_type']].format(subtab[kwargs['_link']]))

func(_type='tab', _link='a')
func(_type='tab', _link='b')
func(_type='subtab', _link='subtab1')
func(_type='subtab', _link='subtab2')

#expect
tab_link:a
tab_link:b
subtab_link:1
subtab_link:2
You can take _type and _link as keyword arguments, and so would simply your code. This can be as simple as func(_type=None, _link=None). However you may want to only take them if they are keyword arguments, and that method would allow them to be passed as normal positional arguments. To do this you can use prepend * to the function to do this. And so you can use func(*, _type=None, _link=None).