Recently in a Python training, Someone asked me how to pass a function as a parameter in Python. After experimenting with this concept, I will explain how to pass a function as a parameter through suitable examples and screenshots of the executed example code.
Functions as Objects
In Python, functions are first-class objects. This means that functions can be assigned to variables, stored in data structures, and passed as arguments to other functions, just like any other object. This property enables us to write higher-order functions that accept functions as parameters.
Let’s consider an example where we have a list of employees in a US-based company:
employees = [
{"name": "John Smith", "salary": 50000},
{"name": "Emma Johnson", "salary": 65000},
{"name": "Michael Davis", "salary": 75000},
{"name": "Olivia Wilson", "salary": 55000}
]Read How to Use the arange() Function in Python?
Pass Functions as Arguments in Python
Suppose we want to calculate the average salary of the employees. We can define a Python function that takes the employees list and a function to extract the salary from each employee dictionary:
def average_salary(employees, salary_extractor):
total_salary = sum(salary_extractor(employee) for employee in employees)
return total_salary / len(employees)Here, salary_extractor is a function that takes an employee dictionary and returns the salary. We can define this function separately:
def get_salary(employee):
return employee["salary"]Now, we can pass the get_salary function as an argument to average_salary:
avg_salary = average_salary(employees, get_salary)
print(f"The average salary is: ${avg_salary:.2f}")Output:
The average salary is: $61250.00In the screenshot below you can see the executed example code with the output.

Check out How to Convert a String to a Float in Python?
Example: Filter Employees
Let’s consider a real-world scenario where we need to filter employees based on specific criteria. We can define a function that takes the employees list and a predicate function to determine if an employee should be included in the filtered list:
def filter_employees(employees, predicate):
return [employee for employee in employees if predicate(employee)]Now, let’s say we want to filter employees whose salary is above $60,000. We can define a predicate function for this:
def salary_above_60k(employee):
return employee["salary"] > 60000We can then pass the salary_above_60k function as an argument to filter_employees:
high_earners = filter_employees(employees, salary_above_60k)
print("Employees with salary above $60,000:")
for employee in high_earners:
print(f"{employee['name']} - ${employee['salary']}")Output:
Employees with salary above $60,000:
Emma Johnson - $65000
Michael Davis - $75000In the screenshot below you can see the executed example code with the output.

Read How to Remove Spaces from String in Python?
Pass Lambda Functions
Instead of defining separate functions, we can also use Python lambda functions (anonymous functions) to pass as arguments. Lambda functions are concise and can be defined inline.
Let’s modify the previous example to use a lambda function:
high_earners = filter_employees(employees, lambda emp: emp["salary"] > 60000)This achieves the same result as before but without the need for a separate salary_above_60k function.
Check out How to Use the insert() Function in Python?
Partial Function Application
Sometimes, we may need to Python pass a function with some of its arguments already filled out. This is known as a partial function application. Python provides the functools.partial function to create partial functions.
Let’s say we want to calculate the tax amount for each employee, given a tax rate. We can define a function to calculate the tax:
def calculate_tax(salary, tax_rate):
return salary * tax_rateTo create a partial function with a fixed tax rate of 0.22 (22%), we can use functools.partial:
from functools import partial
calculate_tax_22_percent = partial(calculate_tax, tax_rate=0.22)Now, we can use the calculate_tax_22_percent partial function to calculate the tax for each employee:
def get_employee_tax(employee):
salary = employee["salary"]
tax = calculate_tax_22_percent(salary)
return {"name": employee["name"], "tax": tax}
employee_taxes = [get_employee_tax(employee) for employee in employees]
print("Employee taxes:")
for employee_tax in employee_taxes:
print(f"{employee_tax['name']} - Tax: ${employee_tax['tax']:.2f}")Output:
Employee taxes:
John Smith - Tax: $11000.00
Emma Johnson - Tax: $14300.00
Michael Davis - Tax: $16500.00
Olivia Wilson - Tax: $12100.00Read How to Use the strip() Function in Python?
Conclusion
In this tutorial, I have explained how to pass a function as a parameter in Python. We discussed functions as objects, how to pass functions as arguments, real-time example, pass lambda function, partial function application.
You may like to read:
- How to Use the trim() Function in Python?
- How to Use the Floor() Function in Python?
- How to Use the round() Function in Python?

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.