Home » Python

Python | Example of function as return value

Python Example of function as return type: Here, we are going to learn how we can return a function as return value in Python?
Submitted by Pankaj Singh, on October 14, 2018

Example:

Here, we are defining two function foo() and koo(), function koo() will return as a value (return value of the function).

The calling statement is x=koo() - where, koo() is first function and the return value of koo() (that is the function foo()) will store in the x (which is also a function).

Code:

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

# defining an another function
# it will return function as a return value
def koo():
    return foo

# function calling and assigning return value
# in x
x=koo()
x()

Output

I am Foo





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




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.