python面向对象之:细分类的组成成员
https://www.oldboyedu.com/zuixin_wenzhang/index/id/540.html
https://blog.csdn.net/loner_fang/article/details/80877491
https://blog.csdn.net/weixin_42124234/article/details/90317389
https://blog.csdn.net/u013066730/article/details/99940019子父类
#code=utf-8
class A:
def __init__(self):
print("hello")
def say(hehe): //可以不写成self 类函数必须要有个参数
hehe.gg='123' //实例变量可以定义在__init之外__
print("say hello")
def show(): 相当于静态函数
print('show')
def ww(self):
self.say()#类函数相互调用
print("hahhhhh")
a=A()
a.say() 反编译 为 A.say(a)
A.show() 必须用类名才能调用
如果在子类中需要父类的构造方法就需要显式地调用父类的构造方法,或者不重写父类的构造方法。
子类不重写 __init__,实例化子类时,会自动调用父类定义的 __init__。
如果重写了__init__ 时,要继承父类的构造方法,可以使用 super 关键字:
在调用基类的方法时,需要加上基类的类名前缀,且需要带上 self 参数变量。区别在于类中调用普通函数时并不需要带上 self 参数
def __init__(self, name):
super().__init__(name)