十分钟学会Python, 简单入门教程(16)

http://www.smzswang.com时间:2016-10-23 14:21来源:未知

  # it what's called a "new-style class".

  # Multiple inheritance is declared as:

  # class OtherClass(MyClass1, MyClass2, MyClassN)

  class OtherClass(MyClass):

  # The "self" argument is passed automatically

  # and refers to the class instance, so you can set

  # instance variables as above, but from inside the class.

  def __init__(self, arg1):

  self.myvariable = 3

  print arg1

  >>> classinstance = OtherClass("hello")

  hello

  >>> classinstance.myfunction(1, 2)

  3

  # This class doesn't have a .test member, but

  # we can add one to the instance anyway. Note

【免责声明】本文仅代表作者个人观点,与中国数码招商网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。您若对该稿件内容有任何疑问或质疑,请联系本网将迅速给您回应并做处理。

相关新闻