问答详情
源自:2-13 python中编写带参数decorator

if unit = 'ms':这句单独用语法出错了吗

import time

def performance(unit):
    def printf(f):
        def dota_time(*args,**kw):
            t1 = time.time()
            r = f(*args,**kw)
            t2 = time.time()
            if unit = 'ms':
                t = t2-t1*1000
            else:
                t = t2-t1
            print 'call %s() in %f%s' % (f.__name__,t,unit)
            return r
        return dota_time
    return printf


@performance('ms')
def factorial(n):
    return reduce(lambda x,y: x*y, range(1, n+1))

print factorial(10)

为什么我的报错了  if unit = 'ms':说这句语法错误

提问者:qq_幕布斯0364116 2019-08-15 22:26

个回答

  • qq_幕布斯0364116
    2019-08-15 22:28:13

    我知道了,=是赋值要用==