ADVERTISEMENT
ADVERTISEMENT

Python program to return function from another function

Here, we will write a Python program with a function that returns another function.
Submitted by Shivang Yadav, on March 19, 2021

Python allows programmers to return a function from another function like it allows function as an argument.

This is possible because python treats its functions as class objects.

Program to return a function from another function

# function - foo()
def foo():
    print("I am Foo")

# function - koo() returning foo
def koo():
    return foo

# calling the koo()
x=koo()
# calling function returned by koo()
x()

Output:

I am Foo

Python Basic Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.