美文网首页
链式/装饰器...

链式/装饰器...

作者: zzjack | 来源:发表于2017-10-27 17:21 被阅读0次

    链式

    class person:
        def name(self,name):
            self.name = name
            return self
        def age(self,age):
            self.age = age
            return self
        def show(self):
            print(f"my name is {self.name},and i am {self.age}")
    

    装饰器

    1. 函数装饰器
    def print_args(function):
        def wrapper(*args,**kwargs):
            print(f"function => {function.__name__};argument => {args},{kwargs}")
            return function(*args,**kwargs)
        return wrapper
    

    bool value is false

    False    None    0   ""    ()    []   {}
    

    these bool values are false. you can use when needing to judge var if was empty

    if not a:
      ...
    

    随机获取list值

    a = [1,2,3,4]
    random.choice(a)
    ``

    相关文章

      网友评论

          本文标题:链式/装饰器...

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