<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: XZM27</title>
    <description>The latest articles on DEV Community by XZM27 (@xzm27).</description>
    <link>https://dev.to/xzm27</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F906127%2Fc5cb477a-8d85-4675-b15a-d5222a15dce0.jpeg</url>
      <title>DEV Community: XZM27</title>
      <link>https://dev.to/xzm27</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/xzm27"/>
    <language>en</language>
    <item>
      <title>Wordle with python</title>
      <dc:creator>XZM27</dc:creator>
      <pubDate>Wed, 17 Aug 2022 05:29:57 +0000</pubDate>
      <link>https://dev.to/xzm27/wordle-with-python-460k</link>
      <guid>https://dev.to/xzm27/wordle-with-python-460k</guid>
      <description>&lt;p&gt;&lt;strong&gt;Lets create the famous wordle game in python&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How the game works:

&lt;ul&gt;
&lt;li&gt;learn by playing it yourself: 
&lt;a href="https://www.nytimes.com/games/wordle/index.html"&gt;wordle&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Prerequisite:

&lt;ul&gt;
&lt;li&gt;classes and objects&lt;/li&gt;
&lt;li&gt;pip install clrprint&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Basic template&lt;/strong&gt;&lt;br&gt;
lets create the basic template for the game&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import random
from clrprint import *


class Wordle:
    """main game class"""
    def __init__(self: object) -&amp;gt; None:
        """initialize attributes"""
        # word list and current word
        self.words = ["HELLO","WORLD","CRANE","BREAD",
                      "GIVER","GREAT","NEVER"]
        self.current_word = random.choice(self.words)

        self.current_row = 0

        self.letter_found = False

    def run_game(self: object) -&amp;gt; None:
        """main game runner class"""
        while self.current_row &amp;lt; 6 and not self.letter_found:
            pass       


if __name__ == "__main__":
    w_game = Wordle()
    w_game.run_game()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;__init__&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Firstly we import &lt;code&gt;random&lt;/code&gt; and &lt;code&gt;clrprint&lt;/code&gt;. We will use &lt;code&gt;clrprint&lt;/code&gt; to give colored outputs in our shell.&lt;/li&gt;
&lt;li&gt;We define the main game class &lt;code&gt;Wordle&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;We create a list of words &lt;code&gt;self.words&lt;/code&gt; out of which one will be the current word &lt;code&gt;self.current_word&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;More words can be added to &lt;code&gt;self.words&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;We get the &lt;code&gt;self.current_word&lt;/code&gt; using &lt;code&gt;random.choice(self.words)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;We initialize &lt;code&gt;self.current_row&lt;/code&gt;. This will help us to keep track when the player has exhausted 6 tries.&lt;/li&gt;
&lt;li&gt;We set &lt;code&gt;self.letter_found = False&lt;/code&gt; so that when the letter is found we can stop the game&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;run_game&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This contains the while loop for the game.&lt;/li&gt;
&lt;li&gt;We run the while loop until the player has exhausted his tries or the player finds the word.&lt;/li&gt;
&lt;li&gt;For the moment we run pass&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;&lt;strong&gt;starting the game&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We create the objeect of &lt;code&gt;Wordle&lt;/code&gt; as &lt;code&gt;w_game&lt;/code&gt; under &lt;code&gt;if __name__ == "__main__":&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;We call the &lt;code&gt;run_game&lt;/code&gt; method using &lt;code&gt;w_game.run_game()&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Taking user input and incrementing &lt;code&gt;self.current_row&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
Alright now we need to take the users input.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The user input must have a length of 5&lt;/li&gt;
&lt;li&gt;It must be contained in "self.words"&lt;/li&gt;
&lt;li&gt;If the input is valid then we increment &lt;code&gt;self.current_row&lt;/code&gt; by 1
Lets create a method &lt;code&gt;_check_row&lt;/code&gt; to accomplish this and we will call &lt;code&gt;_check_row&lt;/code&gt; in the while loop.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;--snip--
    def run_game(self: object) -&amp;gt; None:
        """main game runner class"""
        while self.current_row &amp;lt; 6 and not self.letter_found:
            self._check_row()

    def _check_row(self: object) -&amp;gt; None:
        """"handle the try count"""
        print(f"Number of tries: {self.current_row + 1}")
        user_word = input("enter word: ").upper()
        if len(user_word) == 5 and user_word in self.words:
            self.current_row += 1
            self.compare_word(user_word)
        else:
            print("input five letter word which is in word list")

    def compare_word(self: object, user_input: str) -&amp;gt; None:
        """compare user input to current word"""
        pass

--snip--
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;run_game&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We call the freshly baked &lt;code&gt;_check_row&lt;/code&gt; in the while loop&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;_check_row&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We print the current number of tries of the player&lt;/li&gt;
&lt;li&gt;We take the users input &lt;code&gt;user_word&lt;/code&gt; and use &lt;code&gt;.upper()&lt;/code&gt; to covert the user input into uppercase&lt;/li&gt;
&lt;li&gt;We check if the input is valid or not&lt;/li&gt;
&lt;li&gt;For a valid input we increment &lt;code&gt;self.current_row&lt;/code&gt; by 1&lt;/li&gt;
&lt;li&gt;We need some logic to comapre the user input with our &lt;code&gt;self.current_word&lt;/code&gt;. We create a new method for that called &lt;code&gt;compare_word&lt;/code&gt;and leave it with &lt;code&gt;pass&lt;/code&gt; for the moment.&lt;/li&gt;
&lt;li&gt;If the user input is invalid we do not incrememnt &lt;code&gt;self.current_row&lt;/code&gt; and humbly ask the user to input a five letter word which is in &lt;code&gt;self.words&lt;/code&gt;.
We can run the game now. For valid inputs the tries will increment and when we reach 6 tries the game will stop. So far so good, but we still need to give the game its backbone logic.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Comparing the user input and urrent word and adding logic&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Wordle logic:

&lt;ul&gt;
&lt;li&gt;If the letter is not in the actual word: grey&lt;/li&gt;
&lt;li&gt;If the letter is in the actual word and in the correct position: green&lt;/li&gt;
&lt;li&gt;If the letter is in the actual word and not in the correct position: yellow&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can implement this logic easily enumerate(). Also if the player finds the word we want to stop the game.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;--snip--
    def compare_word(self: object, user_input: str) -&amp;gt; None:
        """compare user input to current word"""
        if user_input == self.current_word:
                clrprint("You found the letter", clr="red")
                self.letter_found = True

        else:
            for letter_index, letter in enumerate(user_input):
                if letter == self.current_word[letter_index]:
                    clrprint(f"{letter} is in the word and in correct position", clr="green")
                elif letter in self.current_word:
                    clrprint(f"{letter} is in the word but not in correct position", clr="yellow")
                else:
                    print(f"{letter} is not in the word")
--snip--
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;compare_word(self: object, user_input: str) -&amp;gt; None&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;compare_word&lt;/code&gt; method takes an argument &lt;code&gt;user_input&lt;/code&gt; which is the user input.&lt;/li&gt;
&lt;li&gt;Firstly we check if the user has found the word.&lt;/li&gt;
&lt;li&gt;If the user finds the word we print a congatulations message and then set &lt;code&gt;self.letter_found&lt;/code&gt; to True. This stops the while loop from running and ends the game.&lt;/li&gt;
&lt;li&gt;clrprint allows us to give colored outputs in the shell.&lt;/li&gt;
&lt;li&gt;If the word is not found we implement our logic part.&lt;/li&gt;
&lt;li&gt;In the for loop we iterate through &lt;code&gt;user_input&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.programiz.com/python-programming/methods/built-in/enumerate"&gt;enumerate()&lt;/a&gt; adds a counter to the iterable and returns it.&lt;/li&gt;
&lt;li&gt;We store two iterating variables- &lt;code&gt;letter_index&lt;/code&gt;, &lt;code&gt;letter&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;We then check if &lt;code&gt;letter&lt;/code&gt; matches &lt;code&gt;self.current_word[letter_index]&lt;/code&gt;. This compares the letter in both user input and current word at the same positions.&lt;/li&gt;
&lt;li&gt;If the letter is not found in the same position we check if the letter is in the current word.&lt;/li&gt;
&lt;li&gt;If none of the above holds truthy we output that the letter is not in the word.&lt;/li&gt;
&lt;li&gt;We do this checking for every letter in the user input using the for loop.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;SOURCE CODE&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import random
from clrprint import *


class Wordle:
    """main game class"""
    def __init__(self: object) -&amp;gt; None:
        """initialize attributes"""
        # word lst and current word
        self.words = ["HELLO","WORLD","CRANE","BREAD","GIVER","GREAT","NEVER"]
        self.current_word = random.choice(self.words)

        self.current_row = 0

        self.letter_found = False

    def run_game(self: object) -&amp;gt; None:
        """main game runner class"""
        while self.current_row &amp;lt; 6 and not self.letter_found:
            self._check_row()

    def _check_row(self: object) -&amp;gt; None:
        """"handle the try count"""
        print(f"Number of tries: {self.current_row + 1}")
        user_word = input("enter word: ").upper()
        if len(user_word) == 5 and user_word in self.words:
            self.current_row += 1
            self.compare_word(user_word)
        else:
            print("input five letter word which is in word list")

    def compare_word(self: object, user_input: str) -&amp;gt; None:
        """compare user input to current word"""
        if user_input == self.current_word:
                clrprint("You found the letter", clr="red")
                self.letter_found = True

        else:
            for letter_index, letter in enumerate(user_input):
                if letter == self.current_word[letter_index]:
                    clrprint(f"{letter} is in the word and in correct position", clr="green")
                elif letter in self.current_word:
                    clrprint(f"{letter} is in the word but not in correct position", clr="yellow")
                else:
                    print(f"{letter} is not in the word")



if __name__ == "__main__":
    w_game = Wordle()
    w_game.run_game()

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The game is now ready to be played. Add more words to &lt;code&gt;self.words&lt;/code&gt; to make the game more challenging. &lt;/p&gt;

&lt;p&gt;From the author: &lt;br&gt;
Please do comment any improvements/ bugs in the game. Thank you for reading and learning :)&lt;/p&gt;

</description>
      <category>python</category>
      <category>tutorial</category>
      <category>gamedev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Decorators part II</title>
      <dc:creator>XZM27</dc:creator>
      <pubDate>Wed, 10 Aug 2022 06:22:42 +0000</pubDate>
      <link>https://dev.to/xzm27/decorators-part-ii-dmo</link>
      <guid>https://dev.to/xzm27/decorators-part-ii-dmo</guid>
      <description>&lt;p&gt;This is a continuation to the previous post &lt;a href="https://dev.to/xzm27/decorators-in-python-4cmd"&gt;decorators in python&lt;/a&gt;.&lt;br&gt;
Previously we passed the function &lt;code&gt;display&lt;/code&gt; into the decorator function. But what if the &lt;code&gt;display&lt;/code&gt; function has some arguments that it takes?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def decorator_function(original_function):
    def wrapper_function():
        #do something before the function
        print("hello from wrapper")
        return original_function()
    return wrapper_function


#this works same as decorator_function(display)
@decorator_function
def display():
    print("hello from display")

display()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Passing arguments into decorators&lt;/strong&gt;&lt;br&gt;
lets pass down some arguments in &lt;code&gt;display&lt;/code&gt; and see what happens.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@decorator_function
def display(name, age):
    print(f"hello from {name}. I am {age} years old.")

display("Dev", 15)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TypeError: wrapper_function() takes 0 positional arguments but 2 were given
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It throws an error because right now the wrapper function cannot take any arguments. This can be fixed by using &lt;code&gt;*args&lt;/code&gt; and &lt;code&gt;**kwargs&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def decorator_function(original_function):
    def wrapper_function(*args, **kwargs):
        #do something before the function
        print("hello from wrapper")
        return original_function(*args, **kwargs)
    return wrapper_function


#this works same as decorator_function(display)
@decorator_function
def display():
    print(f"hello from {name}. I am {age} years old.")

display("Dev", 15)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;*args&lt;/code&gt; allows us to pass any number of positional arguments and &lt;code&gt;**kwargs&lt;/code&gt; allows us to pass any number of keyword arguments into the &lt;code&gt;wrapper_function&lt;/code&gt;. Now we can pass any number of arguments into our decorated function.&lt;br&gt;
&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;hello from wrapper
hello from dev. I am 15 years old
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thank you for reading and learning.&lt;/p&gt;

</description>
      <category>python</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Decorators in python</title>
      <dc:creator>XZM27</dc:creator>
      <pubDate>Tue, 09 Aug 2022 22:12:00 +0000</pubDate>
      <link>https://dev.to/xzm27/decorators-in-python-4cmd</link>
      <guid>https://dev.to/xzm27/decorators-in-python-4cmd</guid>
      <description>&lt;p&gt;&lt;strong&gt;Decorators: end you everlasting confusion about decorators and its uses&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Whenever going through github or any other codebase, we often come across somthing that looks unlike python.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@decorator
def my_function():
    pass
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is known as a decorator in python and is extremely handy and powerful. A decorator is used when we need to change the behaviour of a function without changing the function itself. Makes sense? It will now.&lt;br&gt;
It can be said that &lt;em&gt;almost everything in python is an object&lt;/em&gt;. Functions are also objects(first class). Therefore we can assign functions to a variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def my_function():
    print("hello dev community")

#we can assign the function without executing to the variable func
func=my_function
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Functions are first class objects&lt;/strong&gt;&lt;br&gt;
They can be assigned to a varibale as shown earlier.&lt;br&gt;
Moreover they can be passed as argument to another function and also nested into another function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def outer(message):
    def inner():
        print("hi "+ message)
    return inner

hi = outer("dev community")
bye = outer("dev community")

#this executes the inner function.
hi()
bye()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;hi dev community
bye dev community
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we have two nested function &lt;code&gt;outer&lt;/code&gt; and &lt;code&gt;inner&lt;/code&gt;&lt;br&gt;
&lt;code&gt;outer&lt;/code&gt; returns &lt;code&gt;inner&lt;/code&gt; without executing it. When we assign &lt;code&gt;outer&lt;/code&gt; to a variable and execute the variable,it actually executes &lt;code&gt;inner&lt;/code&gt; with the specific argument.&lt;br&gt;
This is called a closure. Closures can avoid the use of global values and provides some form of data hiding. It can also provide an object oriented solution to the problem.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Decorators extensively use closures&lt;/strong&gt;&lt;br&gt;
Rather than taking &lt;code&gt;message&lt;/code&gt; as an argument decorators take functions as arguments.Let's create a decorator step-by-step.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def decorator_function(original_function):
    def wrapper_function():
        #do something before the function
        print("hello from wrapper")
        return original_function()
    return wrapper_function

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

decor_display = decorator_function(display)
decor_display()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code looks extremly similar to the closure we created earlier. We are now passing a function through &lt;code&gt;decorated_function&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;When we assign &lt;code&gt;decor_display&lt;/code&gt; the &lt;code&gt;decorator_function&lt;/code&gt; executes and returns &lt;code&gt;wrapper_function&lt;/code&gt;. We then execute the &lt;code&gt;wrapper_function&lt;/code&gt; stored in &lt;code&gt;decor_display&lt;/code&gt; by invoking &lt;code&gt;decor_display&lt;/code&gt; in the last line. Now the &lt;code&gt;wrapper_function&lt;/code&gt; executes its print statement and the &lt;code&gt;original_function&lt;/code&gt; which in our context is &lt;code&gt;display&lt;/code&gt; and finally outputs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;hello from wrapper
hello from display
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That was a lot to take in for sure.Go through the process again and  hopefully the logic will be clear. &lt;br&gt;
Here we successfully managed to changed the behaviour of the &lt;code&gt;display&lt;/code&gt; function by printing and extra line before it &lt;code&gt;hello from wrapper&lt;/code&gt;. We did not change the &lt;code&gt;display&lt;/code&gt; function itself but rather changed its behaviour using our &lt;code&gt;decorator_function&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Python allows us to do this same thing using &lt;code&gt;@decorator_function_name&lt;/code&gt;. Rather than assigning &lt;code&gt;decorator_function&lt;/code&gt; to a variable we can assign it to any function using &lt;code&gt;@decorator_function&lt;/code&gt; before the function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def decorator_function(original_function):
    def wrapper_function():
        #do something before the function
        print("hello from wrapper")
        return original_function()
    return wrapper_function


#this works same as decorator_function(display)
@decorator_function
def display():
    print("hello from display")

display()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;hello from wrapper
hello from display
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusions&lt;/strong&gt;&lt;br&gt;
Decorators are a powerful tool and is used in many codebases for various purposes such as  logging, performance testing, perform caching, verifying permissions etc. If you find this tutorial useful do comment below. Thank you for reading and learning.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/xzm27/decorators-part-ii-dmo"&gt;decorators part II&lt;/a&gt;-&amp;gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
