类和面向对象
# python 类支持封装、继承、多态
# 类名称首字符大写。建议遵循驼峰语法
# 第一行代码,定义一个空类
class FirstClass(object):
pass
# 类变量和 类方法
class SecondClass(object):
name='张三'
age=30
def introlduction(self):
print("大家好,我叫{},今年{}岁".format(self.name,self.age))
# 构造方法
class ThirdClass(object):
def __init__(self,name,age) -> None:
self.name=name
self.age=age
def introduction(self):
print("大家好,我叫{},今年{}岁".format(self.name,self.age))
T=ThirdClass('张三',30)
T.age=31
T.introduction()
定义一个基类
class Persion(object):
def __init__(self, name):
self.name=name
def aa(fn):
def new(*args,**kwargs):
print('这一行用于判断')
fn(*args,**kwargs)
print('这一行是日志')
return new
@aa
def say(self,address):
print(self.name,address)
派生子类
class BlackPersion(Persion):
def __init__(self, name):
super().__init__(name)
@Persion.aa
def newfn(self):
print(self.name)
b=BlackPersion('zhansan')
b.say('fz')
b.newfn()