Nested Decorators in Python Last Updated : 25 Aug, 2021 Comments Improve Suggest changes Like Article Like Report Everything in Python is an object. Even function is a type of object in Python. Decorators are a special type of function which return a wrapper function. They are considered very powerful in Python and are used to modify the behaviour of a function temporarily without changing its actual value. Nesting means placing or storing inside the other. Therefore, Nested Decorators means applying more than one decorator inside a function. Python allows us to implement more than one decorator to a function. It makes decorators useful for reusable building blocks as it accumulates the several effects together. How several decorators are applied? A function can be decorated multiple times. We need to define the decorator first that we want to wrap the output string with, and then apply them to the function using the '@' . One simply needs to place the decorators above the desired function. Syntax : @function1 @function2 def function(name): print(f"{name}") Nested decorators follow a bottom to top approach i.e the reverse order. It can be related to a construction of building where we start the construction from the bottom (the ground) and then start building the floors. Example : Python3 # Python program to demonstrate # nested decorators def italic(func): def wrapper(): return '<i>' + func() + '</i>' return wrapper def strong(func): def wrapper(): return '<strong>' + func() + '</strong>' return wrapper @italic @strong def introduction(): return 'This is a basic program' print(introduction()) Output: <i><strong>This is a basic program</strong></i> Explanation : We have defined two decorators first, which are used in wrapping the output string of the decorated function in the 'strong' and 'italic' tags of HTML.Then we are applying the two decorators to our 'introduction' function by using just an "@" and the function name. For example in this program we are using @italic and @strong.The hierarchy that it follows is from bottom to top. Therefore according to it the string is wrapped with 'strong' first an then with 'italic'. Comment More infoAdvertise with us Next Article Nested Decorators in Python V vishalraina Follow Improve Article Tags : Python Python Decorators Practice Tags : python Similar Reads Decorators in Python In Python, decorators are a powerful and flexible way to modify or extend the behavior of functions or methods, without changing their actual code. A decorator is essentially a function that takes another function as an argument and returns a new function with enhanced functionality. Decorators are 10 min read Decorators with parameters in Python Prerequisite: Decorators in Python, Function DecoratorsWe know Decorators are a very powerful and useful tool in Python since it allow programmers to modify the behavior of functions or classes. In this article, we will learn about the Decorators with Parameters with the help of multiple examples. P 4 min read call() decorator in Python Python Decorators are important features of the language that allow a programmer to modify the behavior of a class. These features are added functionally to the existing code. This is a type of metaprogramming when the program is modified at compile time. The decorators can be used to inject modifie 3 min read Python Nested Dictionary A Dictionary in Python works similarly to the Dictionary in the real world. The keys of a Dictionary must be unique and of immutable data types such as Strings, Integers, and tuples, but the key values can be repeated and be of any type. What is Python in Nested Dictionary? Nesting Dictionary means 3 min read Chain Multiple Decorators in Python In this article, we will try to understand the basic concept behind how to make function decorators and chain them together we will also try to see Python decorator examples. What is Decorator In Python?A decorator is a function that can take a function as an argument and extend its functionality an 2 min read Like