Python中的构造函数是__init__函数
Python中子类如果定义了构造函数,父类的构造函数是不会执行的。
__init__函数使用方法:
class A:
def __init__(self, name):
self.name = name
class B(A):
def __init__(self, age):
self.age = age
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:python中构造函数有什么用