Python面向对象提升与收发邮件
1.多继承
打印123
class Person(object):
def m(self):
print(“123”)
per = Person()
per.m()
引入
from a import a
2.多态:一种事物的多种形态
定义了一个有name属性和way,methold方法的Vehicle类
import Vehicle
thisVehicle =Vehicle.vehicle(“28路公交车”) #实例化对象
thisVehicle.way() #驾驶类型
thisVehicle =Vehicle.vehicle(“906路公交车”) #实例化对象
thisVehicle.method() #驾驶类型
thisVehicle =Vehicle.vehicle(“B32路公交车”) #实例化对象
thisVehicle.way() #驾驶类型
#定义了一个有name属性和way,methold方法的Vehicle类
class vehicle(object):
def init(self, name): #定义函数
self.name = name
print(self.name)
def way(self): #定义驾驶方法
print(self.name + “自动挡汽车驾驶”) #驾驶方法之一
def method(self): #定义驾驶方法
print(self.name + “手动挡汽车驾驶”) #驾驶方法之一
3.对象属性与类属性
类属性–用类名来调用
对象属性的优先性高于类属性
类属性——类调用
对象属性-——对象调用
#动态的给对象添加属性——只对于当前对象生效,对于类创建的其他对象没有作用
删除对象属性(del)(不会报错),在调用时会使用到同名的类属性
注意:不要让对象属性和类属性性重名,因为对象属性会屏蔽掉类属性。但是删除对象属性后,就又能使用类属性了