代码示例:(标识:python_inheritance_parent)
python_inheritance_parent.py
class Person:
  def __init__(self, fname, lname):
    self.firstname = fname
    self.lastname = lname

  def printname(self):
    print(self.firstname, self.lastname)

#Use the Person class to create an object, and then execute the printname method:

x = Person("Bill", "Gates")
x.printname()
运行结果: