Loop Control Statements in C Introduction to HTML How to use the Github API The image tag, anchor tag and the button tag Ordered and Unordered Lists in HTML The division tag HTML Forms Tables in HTML Introduction to C Programming Introduction to Python Varibles and Datatypes in Python Operators in Python Typecasting in Python Input and Output in Python If Else in Python Loops in Python Break, Continue and Pass in Python Python practice section 1 Lists in Python Tuple in Python

Higher order functions in Python

In Python, functions are called first-class objects i.e. they can be passed as parameters to other functions or one function can be returned by another function. The functions that use or returns other functions are called Higher-order functions. Consider the following code.

def hello(name):
    print("Hello,",name)

def func(func2):
    print("Calling hello")
    func2("rapid coders")

print("Calling func")

func1(hello)
    
Output
Calling func1
Calling hello
Hello, rapid coders
    
Functions can also be assigned to variables. For example -.

def hello():
    print("hello from python")

hello_python=hello
print(hello_python())
    
Output
hello from python
        
A function can also return another function.

def hello1():
    print("hello from python")

    def hello2():
        print("hello from rapid coders!")
        
    return hello2()

func=hello1()  
print("Calling func")      
func()
    
Output
hello from python
Calling func
hello from rapid coders!