Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

# decorator

# decorator function
def outer(func):
    def inner():
        str1 = func() 
        return str1.upper() # addition of functionality
    return inner

@outer 
def print_str():
    return "good morning"

print(print_str())

# Output -> 'GOOD MORNING'
# A decorator is a function that takes another function as an argument, adds some kind of functionality to it and returns another function. Python decorators help add functionality to an existing code(function) which may aid in code reusability. 
Comment

basic decorator example

def log_result(func):
  def inner():
    res = func()
    print(res)
    return res
Comment

PREVIOUS NEXT
Code Example
Python :: Closing small holes in the binary image with opencv 
Python :: python sliding window maximum 
Python :: empty show non python 
Python :: imoport python code 
Python :: pandas fast way to view distribution by group 
Python :: how to create a sub project in django 
Python :: data[:,:2] 
Python :: python copy file create intermediate directories 
Python :: how many python programmers in the world 
Python :: python or in if statement 
Python :: provide a script that prints the sum of every even numbers in the range [0; 100]. 
Python :: why we need open ( ) and close ( ) in os 
Python :: how to stop gambling 
Python :: in python, i am pustin two star before paramerter what is that men 
Python :: returns the dataframe with the modified Title column in which the updated groupings are reflected. 
Python :: The module in NAME could not be imported: django.contrhtmlib.auth.password_validation.UserAttributeSimilarityValidator. Check your AUTH_PASSWORD_VALIDATORS setting. 
Python :: 2d grid python pygame 
Python :: discord py aliases 
Python :: [E053] Could not read config.cfg from C:UsershpAppDataLocalProgramsPythonPython37libsite-packages esume_parserdegreemodelconfig.cfg 
Python :: python creare una list comprehension 
Python :: in python how to end the code after 10 input 
Python :: celery subprocess 
Python :: python setup install_requires local whl 
Python :: Distace between two object on a sky map in degress using Ra and Dec 
Python :: arabert 
Python :: problem with console writeline python 
Python :: Recursive Folder scan 
Python :: get data from keyboard python 
Python :: what is norways politics 
Python :: updating file multiple times in pandas 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =