Python syntax sugar, python syntax sugar
#-*-Coding: UTF-8 -*-
Def deco (func ):
Print ("before myfunc () called .")
Func ()
Print ("after myfunc () called .")
Return func
Bool = 0
@ Deco # Here we can see that @ time is equivalent to time (xxx (), but you must consider the execution sequence of python code in this way.
Def myfunc ():
Global bool
Bool = bool + 1
If not bool = 2:
Print ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ")
Bool = 1
Myfunc ()
This function is implemented without syntactic sugar.
#-*-Coding: UTF-8 -*-
Def deco (func ):
Print ("before myfunc () called .")
Func ()
Print ("after myfunc () called .")
Return func
Bool = 0
# @ Deco
Def myfunc ():
Global bool
Bool = bool + 1
If not bool = 2:
Print ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ")
Bool = 1
# Myfunc ()
Deco (myfunc)
Passing Parameters
Def bar (* param1, ** param2 ):
Print param1
Print param2
Def foo (bar, * param1, ** param2 ):
Bar (* param1, ** param2)
Foo (bar, 1, 2, 3, a = 111, B = 222, c = 333)