A callable is a Python object that can be invoked with parentheses. Functions and classes are callables, so a menu can map user-entered keywords to actions and invoke the selected value. section 9.6 section 10.8
Use callables to separate input selection from the operation that follows:
- Accept any number of keyword arguments whose values are callables. section 9.6
- Invoke the callable associated with matching user input and return its result. section 9.6
- Reject unknown input with an error message, then ask again. section 9.6
from menu import menu
def func_a():
return "A"
def func_b():
return "B"
return_value = menu(a=func_a, b=func_b)
print(f'Result is {return_value}')
This executable example maps a and b to separate functions, then prints the selected callable's returned value. section 9.6




