VOOZH about

URL: https://www.geeksforgeeks.org/python/store-functions-in-list-and-call-in-python/

⇱ Store Functions in List and Call in Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Store Functions in List and Call in Python

Last Updated : 23 Jul, 2025

In Python, a list of functions can be created by defining the tasks and then adding them to a list. Here’s a simple example to illustrate how to do this:


Output
Hello!

Let's Explore some other methods to store functions and call them in lists.

Calling Functions with Arguments from a List

Functions can also accept arguments. You can store functions that take parameters in a list and pass the necessary arguments when calling them.


Output
Addition: 15

The add function is stored in the operations list, and it's called using indexing with arguments 10 and 5 to perform the addition.

Dynamic Function Call Using Loops

Using loops to call functions simply allows us to iterate over the list and execute each function dynamically without needing to call them one after the other.


Output
10

The list operations stores two functions, add and subtract and the for loop goes through each function in the list and calls it with the same argument (a = 8, b = 2).

Using List Comprehension to Call Functions

We can use list comprehension to call functions stored in a list and store their results in a new list. This method makes the code more compact and readable when dealing with simple function calls.


Output
Results: [15]

By iterating over the list, each function is invoked with the specified arguments, and the results are stored in a new list.

Storing Lambda Functions in a List

Lambda functions can be stored in a list just like normal functions, which is dynamic and allows flexible execution without explicitly naming the functions.


Output
Multiplication: 18

It demonstrate about lambda functions can be stored in a list and called through indexing. It stores a multiplication lambda function in the list and then calls it with the respective arguments, outputting the result.

Comment