+ 1

It works in this way too, but why is it bettwr with decor func?

def wrap(func): print("============") func() print("============") return wrap def print_text(): print("Hello world!") wrap(print_text)

5th Sep 2016, 9:24 AM
Marco Caso
Marco Caso - avatar
2 Réponses
+ 3
def decor(tag): tag1 = "<"+tag+">" tag2 = "</"+tag+">" def wrap(word): print(tag1+word+tag2) return wrap h1 = decor("h1") p = decor("p") h1("Title 1") p("Content of this paragraph") h1("Title 2") p("Here is the second paragraph") # output: """ <h1>Title 1</h1> <p>Content of this paragraph</p> <h1>Title 2</h1> <p>Here is the second paragraph</p> """
6th Sep 2016, 7:00 PM
Giovanni Gatto
Giovanni Gatto - avatar
+ 2
it's very useful , if you need to do it the same thing many times you can use print("============") at the line above and below your code, but if you use decor function , you can code it easier and faster.
5th Sep 2016, 1:48 PM
beauty1234