python练习(3)

作者: 圆圆KK | 来源:发表于2019-01-06 19:02 被阅读5次

这周有点松懈了,主要是练习MYSQL的应用,为了工作方便,应用到mysql数据库,python方面主要是学习了装饰器。
装饰器分为有参数、无参数。
无参数:

def  w(f):
    def hello():
        print('hello!')
         f()
    return hello()

@w()
def hi():
     print('hi') #等同于w(hi)

有参数:需要用到*args, **kwargs

def  w(f):
    def hello(*args, **kwargs):
        print('hello!')
         f(*args, **kwargs)
    return hello()

@w()
def hi(a,b):
     print('hi,%d,%d'%(a,b))

感觉学习过程更重要是应用,有时候学了觉得没问题,但是一到应用就错误百出,还是多练习、实际应用为主。

相关文章

网友评论

    本文标题:python练习(3)

    本文链接:https://www.haomeiwen.com/subject/pbusrqtx.html