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

电商网站开发意义土建找工作去哪个网站

电商网站开发意义,土建找工作去哪个网站,wordpress仿 模板,wordpress路径错误Python super Python 的 super() 函数允许我们显式地引用父类。在继承的情况下#xff0c;当我们想要调用父类函数时#xff0c;它非常有用。 Python super 函数示例 首先#xff0c;让我们看一下我们在 Python 继承教程中使用的以下代码。在该示例代码中#xff0c;父类…Python super Python 的 super() 函数允许我们显式地引用父类。在继承的情况下当我们想要调用父类函数时它非常有用。 Python super 函数示例 首先让我们看一下我们在 Python 继承教程中使用的以下代码。在该示例代码中父类是 Person子类是 Student。代码如下所示。 class Person:# 初始化变量name age 0# 定义构造函数def __init__(self, person_name, person_age):self.name person_nameself.age person_age# 定义类方法def show_name(self):print(self.name)def show_age(self):print(self.age)# 子类定义开始 class Student(Person):studentId def __init__(self, student_name, student_age, student_id):Person.__init__(self, student_name, student_age)self.studentId student_iddef get_id(self):return self.studentId # 返回学生 ID 的值# 子类定义结束# 创建父类对象 person1 Person(Richard, 23) # 调用对象的成员方法 person1.show_age() # 创建子类对象 student1 Student(Max, 22, 102) print(student1.get_id()) student1.show_name()在上面的示例中我们调用了父类函数如下 Person.__init__(self, student_name, student_age) 我们可以用以下方式替换为 python super 函数调用。 super().__init__(student_name, student_age)输出在两种情况下都将保持不变如下图所示。 Python 3 super 请注意上述语法适用于 Python 3 的 super 函数。如果你使用的是 Python 2.x 版本则略有不同你需要做以下更改 class Person(object): ...super(Student, self).__init__(student_name, student_age)第一个更改是将 object 作为 Person 的基类。在 Python 2.x 版本中使用 super 函数是必需的。否则你将会收到以下错误。 Traceback (most recent call last):File super_example.py, line 40, in modulestudent1 Student(Max, 22, 102)File super_example.py, line 25, in __init__super(Student, self).__init__(student_name, student_age) TypeError: must be type, not classobjsuper 函数本身的语法也有所改变。正如你所看到的Python 3 的 super 函数使用起来更加简单语法也更加清晰。 Python super 函数与多层继承 正如我们之前所述Python 的 super() 函数允许我们隐式地引用父类。但在多层继承的情况下它将引用哪个类呢好吧Python 的 super() 总是引用直接的父类。此外Python 的 super() 函数不仅可以引用 __init__() 函数还可以调用父类的所有其他函数。因此在下面的示例中我们将看到这一点。 class A:def __init__(self):print(Initializing: class A)def sub_method(self, b):print(Printing from class A:, b)class B(A):def __init__(self):print(Initializing: class B)super().__init__()def sub_method(self, b):print(Printing from class B:, b)super().sub_method(b 1)class C(B):def __init__(self):print(Initializing: class C)super().__init__()def sub_method(self, b):print(Printing from class C:, b)super().sub_method(b 1)if __name__ __main__:c C()c.sub_method(1)让我们看看上述 Python 3 多层继承的示例输出。 Initializing: class C Initializing: class B Initializing: class A Printing from class C: 1 Printing from class B: 2 Printing from class A: 3因此从输出中我们可以清楚地看到首先调用了类 C 的 __init__() 函数然后是类 B最后是类 A。通过调用 sub_method() 函数也发生了类似的事情。 为什么我们需要 Python 的 super 函数 如果你之前有 Java 语言的经验那么你应该知道在那里也称为 super 对象的基类。因此这个概念对于程序员来说实际上是有用的。然而Python 也保留了使用超类名称来引用它们的功能。而且如果你的程序包含多层继承那么这个 super() 函数对你很有帮助。所以这就是关于 Python super 函数的全部内容。希望你理解了这个主题。如果有任何疑问请在评论框中提问。
http://www.pierceye.com/news/449822/

相关文章:

  • 手机版企业网站php西宁做网站公司排名
  • 微网站如何做推广做淘宝客网站需要备案吗
  • 天津网站制作重点windows与wordpress
  • 可以查企业备案的网站吗佛山住房和城乡建设部网站官网
  • 和初中生做视频网站怎么进入追信魔盒网站开发软件
  • 邯郸开发网站有哪些阳江市房产信息网
  • 快速网站推广公司丹阳房产网二手房
  • 做一个卖东西的网站黄村做网站的公司
  • 网站增长期怎么做广州seo推广优化
  • 怎么做拍卖网站吗免费网站推广入口
  • 农产品网站建设的主要工作岳阳seo招聘
  • 每年网站备案抽查惠州营销网站建设
  • 四川网站建设seo友汇网网站建设
  • 企业家居网站建设做公司网站方案
  • 特性设计的网站营销型网站建设的五力原则
  • 网站布局设计工具装修室内设计培训学校
  • 哈尔滨网络科技公司做网站中国建设官方网
  • 紫川网站建设做画找图网站
  • 郑州快速建站公司合肥学做网站app的学校
  • 除了做视频网站还能做什么网站wordpress手机站如何做
  • 域名注册最好的网站人才网站
  • 网站建设咨询云尚网络中铁十二局出国招工
  • 建站系统推荐做网站在哪里做
  • 贵州建设工程招标协会网站wordpress黑白主题
  • 怎么免费建立自己网站扁平化网站设计
  • 可以自己做漫画的网站北仑营销型网站制作
  • 免费网站统计代码有什么样的网站开发
  • 文山微网站建设湖南人工智能建站系统软件
  • 做网站时候编代码wordpress 技术博客主题
  • 成立网站建设工作领导小组seo网站关键词优化软件