python——函数修饰符

需要注意的:

  1. 函数先定义,再修饰它;反之会编译器不认识;

  2. 修饰符“@”后面必须是之前定义的某一个函数;

  3. 每个函数只能有一个修饰符,大于等于两个则不可以。

def test(f):
    print "before ..."
    f()
    print "after ..."
 
@test
def func():
    print "func was called"

输出:

before ...
func was called
after ...

你可能感兴趣的:(python——函数修饰符)