""" Peson.py 人类类 edit: ide: date: """ class Human(object): """ 人类类 """ #限制对象属性只能是SLOTS里面的变量名 对象绑定属性,不用先定义属性 #__slots__ = ('sage','sname','sfrom') sage=0 #年龄 sname="geovindu" #名字 sfrom="from china" def __init__(self,name, age,frm): """ :param name: :param age: """ self._name=name self._age=age self._frm=frm def sleeep(self): """ 睡觉 :return: none """ print(id(self)) print(self._age,"岁的",self._name,'在睡觉') def eat(self): """ 吃饭 :return: none """ print(id(self)) print(self._age,"岁的",self._name,"在吃饭") def instrudce(self): """ 自我介绍 :return: none """ print(f"{self._age}岁的{self._name}自我介绍:{self._frm}") def operateAllFunc(self): """ 处理所有方法 :return: none """ self.sleeep() self.eat() self.instrudce()
调用:
p=Peson.Human("geovindu",20,"我是中国人") print(id(p)) #打印内存地址 p.sage=20 p.sname="涂聚文" p.operateAllFunc() print(p.sname) p2=Peson.Human("涂聚文",30,"我是江西人") print(id(p2))#打印内存地址 p2.operateAllFunc()
标签:name,python,self,object,._,print,age,def From: https://www.cnblogs.com/geovindu/p/17489040.html