Things to Know before proceeding for Decorators In Python:
Meta Description:
Introduction:
Calling Functions Inside Functions:
Understanding Function Composition:
By calling one function inside another, we observe the ability to create function compositions. This allows us to build more complex functionality by combining simpler functions.
The above code will return <class 'int'> , Here we see int and str are built in functions in python. from above Python code we can see that we can call a function inside a function.
Different Approaches to Function Composition:
This code will return Hello Harry How are you. Here I Created two user defined functions. function one_fun takes a string as a parameter and return Hello followed by Harry as its input. The trick is here . The second function sec_fun takes first function one_fun as a input and will return How are you after first function called in second function. Some programmer will assign the result of first function to a variable with in second function and then return result. This is depend on coder to coder.
This code will return Hello Harry How are you. but here is some change in approach. created resukt (Please dont go on name i dont know what is this😆) variable and called second function with input of first one but i didnt call first one( When you use bracket after function it means you are calling that function). and i stored the result of this second function in variable. then while printing i called variable(stored value of second function now variable behave as a function) and provide the name as an input. if i give name harry input while assigning function value to resukt it will behave like sec_fun(one_fun("Harry")) code used in above example.
Introduction to Decorators:
Now check last example we have seen second function sec_fun is the function which takes first function one_fun as a parameter, perform a logic inside inner function and return inner function.