#python面向对象 - 类定义
注意:特殊方法"init"前后分别有两个下划线!!!
__init__方法可以理解成定义属性的方法,编辑器中会默认将属性都绑定到self中,在使用时直接self.shuxing 即可哟;
__init__方法中第一位参数永远是self,表示创建实例本身,记住!
class sjlx_03:
#构造方法
def init(self,name,sex):
self._name = name
self._sex = sex
def sayHello(self):
print("20190531:{0},{1}".format(self._name,self._sex))
#如需使用类中方法需实例
s = sjlx_03(“双权”,“女”)
s.sayHello()
打印结果:20190531:双权,女
#python面向对象 - 继承
#python面向对象 - 继承
class hellow(sjlx_03):
def init(self,name):
self._name = name;
def sayHe(self):
print("hellow{0}".format(self._name))
a = hellow(“双权01”)
a.sayHe();
原文:https://www.cnblogs.com/shuangquan/archive/2019/05/31/10955391.html