当前位置: 首页 > wzjs >正文

c 网站开发培训现代感的传媒公司名称

c 网站开发培训,现代感的传媒公司名称,朝阳凌源网站建设,wordpress模板2zztsuper super()是继承父类,那么super().__init__()代表不用实例化就可以调用父类的__init__()方法来对子类进行初始化,那么这就相当于我们实例化了一个对象,那当然需要给super().__init__()指定它的参数了 super() 里面可以不加参数&#xff…

super

super()是继承父类,那么super().__init__()代表不用实例化就可以调用父类的__init__()方法来对子类进行初始化,那么这就相当于我们实例化了一个对象,那当然需要给super().__init__()指定它的参数了

super() 里面可以不加参数,也可以加2个参数(旧写法,放弃)。如果加2个参数: 第一个是子类,第二个参数是该子类实例的对象

class Rectangle:def __init__(self, length, width):self.length = lengthself.width = widthdef area(self):return self.length * self.widthclass Square(Rectangle):def __init__(self, length):super(Square, self).__init__(length, length)

super().__init__(*args, **kwargs)

使用*args**kwargs可以让子类接受任意数量的位置参数和关键字参数,并将它们传递给父类。

class Car(object):def __init__(self, owner, year, model):self.owner = ownerself.year = yearself.model = model def get_info(self):"""打印车辆信息"""print(f'The owner of the car is {self.owner}\n' \f'The model of the car is {self.year}-{self.model}')
class ElectricalCar(Car):def __init__(self, battery, *args):super().__init__(*args)  # 将剩下的参数打包送给superself.battery = battery  # 从参数列表中拿出battery初始化子类属性def get_power(self):"""打印电池信息"""print(f'The battery of this car is {self.battery}')
tesla = ElectricalCar('10000kwh','Jarry', 2021, 'Model S')
tesla.get_info()
tesla.get_power()

The owner of the car is Jarry
The model of the car is 2021-Model S
The battery of this car is 10000kwh
 

单个继承

class Parent:def __init__(self, name):self.name = nameclass Child(Parent):def __init__(self, name, age):super().__init__(name)  # Call parent's constructor firstself.age = ageparent = Parent("Alice")
child = Child("Bob", 12)print("Parent:", parent.name)
print("Child:", child.name, child.age)
Parent: Alice
Child: Bob 12

 Multiple Inheritance

class Base1:def __init__(self, x):self.x = xclass Base2:def __init__(self, y):self.y = yclass Derived(Base1, Base2):def __init__(self, x, y, z):super().__init__(x)  # Call first base class constructor# Call second base class constructor explicitlyBase2.__init__(self, y)self.z = zderived = Derived(1, 2, 3)print("Derived:", derived.x, derived.y, derived.z)

Output

Derived: 1 2 3

Multi-Level Inheritance

class Grandparent:def __init__(self, name):self.name = nameclass Parent(Grandparent):def __init__(self, name, age):super().__init__(name)  # Call grandparent's constructorself.age = ageclass Child(Parent):def __init__(self, name, age, hobby):super().__init__(name, age)  # Call parent's constructorself.hobby = hobbychild = Child("Charlie", 8, "reading")print("Child:", child.name, child.age, child.hobby)

Output

Child: Charlie 8 reading


文章转载自:

http://OQHsEK2S.jhzct.cn
http://6kT0wlMb.jhzct.cn
http://B86bUXmT.jhzct.cn
http://llnaGXHn.jhzct.cn
http://Sv5S8bnj.jhzct.cn
http://ypWKZqNo.jhzct.cn
http://r8JMq3uK.jhzct.cn
http://MCPGhUUm.jhzct.cn
http://cS23kR05.jhzct.cn
http://iDcvSaRW.jhzct.cn
http://TCn7p0s5.jhzct.cn
http://3IGAg9HB.jhzct.cn
http://FLCLcans.jhzct.cn
http://INfT7GeT.jhzct.cn
http://1UQ76M8c.jhzct.cn
http://Sj5Z6K38.jhzct.cn
http://N0G5pQt6.jhzct.cn
http://000Cu3wq.jhzct.cn
http://RAvjC0aC.jhzct.cn
http://zcAnoE5U.jhzct.cn
http://FyRatUt9.jhzct.cn
http://uDYeHUVN.jhzct.cn
http://ADxhCGde.jhzct.cn
http://EWm5He9v.jhzct.cn
http://u3uoFxEn.jhzct.cn
http://yUi9aGLf.jhzct.cn
http://WzF8Z8FR.jhzct.cn
http://scefho7o.jhzct.cn
http://OHuRZWe0.jhzct.cn
http://YHPSqJFs.jhzct.cn
http://www.dtcms.com/wzjs/651253.html

相关文章:

  • 茂名网站建设方案开发ftp 转 wordpress
  • 网站开发培训班 上地网站如何快速免费推广
  • 永康物流网站网络营销推广方式有哪些
  • 中国建设银行曲江支行网站网站制作公司承担
  • 网站从制作到使用的全过程网站开发去哪里找工作
  • 做网站网络合同上海工商局企业信息查询
  • 正规做网站重庆自助企业建站模板
  • 网站搭建前景中国字体设计网官网
  • 上海高端做网站wordpress做出影视网站
  • 做调查问卷网挣钱的网站怎样做校园网站
  • 网站首页模板免费下载深圳正规融资公司
  • 网站建设的项目方案济南建设网站哪里好
  • 专业外贸网站建设 诚信 青岛抖音代运营的好处
  • 个人备案网站百度收录用树莓派做网站服务器速度快吗
  • 什么网站免费做游戏哪个网站做课件ppt比较好
  • 苏州网站制作我的家乡湛江网站设计
  • 成都科技网站建设联如何做信用网站截图
  • 怎么建设空包网站四川省住房与城乡建设厅官方网站
  • 苏州做网站设计的公司有哪些wordpress 自定义头像
  • 手机网站建设如何个人网站公司网站区别经营区别
  • 做品牌网站公司ai设计室内设计
  • 珠宝网站开发wordpress头像加V
  • 将自己做的网站发布到网上成都网站设计最加科技
  • 外贸柒夜网站建设学校网站建设项目可行性分析
  • 本地上海集团网站建设春考网页制作素材
  • 宣城有做网站的公司吗app官网登录入口
  • 查看网站服务器ip无锡公司网站设计
  • 网站备案怎么注销外贸免费网站建设
  • 优秀网页 网站衡水淘宝的网站建设
  • 免费房屋建设图纸网站有哪些中国万网首页