Formatting a string in Python with three possible replacement fields
Build a kwargs dictionary, rather than using an if-else.
You don't have to treat yes and no as mutually exclusive.
You could use a 'key, function' list to create a dictionary comprehension that builds the dictionary for you.


This can lead to:

kwargs = {}
if '{value}' in reply:
    kwargs['value'] = value
if '{yes}' in reply:
    kwargs['yes'] = get_yes()
if '{no}' in reply:
    kwargs['no'] = get_no()
reply = reply.format(**kwargs)




params = [
    ('value', lambda:value),
    ('yes', get_yes),
    ('no', get_no)
]

def format_format(format, params):
    return format.format({
        key: fn()
        for key, fn in params
        if f'{{{key}}}' in format
    })

reply = format_format(reply, params)