特殊方法__init__(self)
class MessageInfo:# 初始化方法def __init__(self, city):self.city = cityself.company = '联通'# 方法def send_email(self, to, body):msg = f'给{to}发送邮件,内容:{body}'print(msg)# 方法def send_dingding(self, to, body):msg = f'给{to}发送邮件,内容:{body}'msg = f'{self.city}给{to}发送邮件,内容:{body}'print(msg)# 类加括号: MessageInfo("北京")
# 1、先创建空对象;
# 2、自动执行:__init__方法 (obj,"北京")
obj = MessageInfo("北京")
# 调用方法
obj.send_email('test@qq.com', '下班了')obj2 = MessageInfo("上海")
# 调用方法
obj2.send_email('test@qq.com', '下班了')