Python Decorators Example

def my_wrapper(func1):
    def func2(l):
        ll = ''.join(reversed(l))
        func1(ll)
    return func2

@my_wrapper
def my_print(l):
    print(l)

if __name__ == '__main__':
    l = input()
    my_print(l)   # Here func2 returned by my_wrapper is called

Input: abcde
Output: edcba
Tested on Python 3.7

Коментари

Публикувай нов коментар

  • Адресите на уеб-страници и e-mail адресите автоматично се конвертират в хипервръзки.
  • Разрешени HTML tag-ове: <a> <p> <span> <div> <h1> <h2> <h3> <h4> <h5> <h6> <img> <map> <area> <hr> <br> <br /> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <em> <b> <u> <i> <strong><font> <del> <ins> <sub> <sup> <quote> <blockquote> <pre> <address> <code> <cite> <embed> <object> <param> <strike> <caption>
  • Линиите и параграфите се прекъсват автоматично.
  • Mark language-dependent sections with == lc == where lc (or lc-xx) is a language code, other or all.

Повече информация за опциите на форматиране

CAPTCHA
5 + 6 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.