python 面向对象与装饰器

面向对象

类(class):现实世界中一些事物的封装(如:学生)

类:属性(如:姓名,成绩)

类对象

实例对象

引用:通过引用对类的属性和方法进行操作

实例化:创建一个类的具体实例对象(如:学生张三)

class Student:
    def __init__(self,name,grade):
        self.name = name
        self.grade = grade
    def introduce(self):
        print("hi , i'm " + self.name)
        print("my grade is :" + str(self.grade))
    def improve(self,amount):
        self.grade = self.grade +amount

  

装饰器(decorator)

Code:

def add_cand(cake_f):
    def insert_cand():
        return  cake_f() +" and cand"
    return insert_cand()
@add_cand
def make_cake():
    return "cake"

print(make_cake())

  

posted @ 2018-02-18 23:26  一个选择  阅读(192)  评论(0)    收藏  举报