#面向对象
class Student:
def __init__(self, name, grade): #self相当于java中的this
self.name = name
self.grade = grade
def introduce(self):
print('hi! I`m ' + self.name)
print('my grade is:' + str(self.grade))
def change_grade(self, new_grade):
self.grade = new_grade
Jim = Student('Jim', 82)
Jim.introduce()
Jim.change_grade(90)
Jim.introduce()
#装饰器的应用
def add_candles(cake_func):
def insert_candles():
return cake_func() + " and candles"
return insert_candles
@add_candles
def make_cake():
return "cake"
print(make_cake())
来源:oschina
链接:https://my.oschina.net/jugier/blog/4269336