Home »
Python
Python | Example of function as argument
Python Example of function as argument: Here, we are going to learn how we can pass a function as an argument in Python?
Submitted by Pankaj Singh, on October 14, 2018
Example:
Here, we are defining two function foo() and koo(), function koo() will take an argument x that will be a function while calling.
The calling statement is koo(foo) - where, koo() is first function and foo() is second function. Function foo() is function as an argument here.
Code:
# defining a function
def foo():
print("I am Foo")
# defining an another passing,
# it will take function as an argument
def koo(x):
x()
# calling first function by passing
# second function as an argument
koo(foo)
Output
I am Foo
Python Tutorial
ADVERTISEMENT
ADVERTISEMENT