In Python, one function can become an argument for another function. This is useful in many cases. Let’s make a calculator function that requires the add, subtract, or multiply function along with two numbers as arguments. For this, we’ll have to define the three arithmetic functions as well.

Using simple functions

In this example, we have several functions for basic arithmetic operations and a calculator function that takes another function as its argument to perform the specified operation.

Get hands-on with 1400+ tech skills courses.