Python基础学习-13
class Person:
def __init__(self, fname, lname):
self.first_name = fname
self.last_name = lname
def print_name(self):
print(self.first_name, self.last_name)
x = Person("猪猪侠", "GGBang")
x.print_name()
class child(Person):
pass
x = child("猪猪侠", "GGBang")
x.print_name()
class Person1:
def __init__(self, fname, lname):
self.first_name = fname
self.last_name = lname
def print_name(self):
print(self.first_name, self.last_name)
class child1(Person):
def __init__(self, fname, lname):
Person1.__init__(self, fname, lname)
X = child1("小龙", "小龙人")
X.print_name()
class Person2:
def __init__(self, fname, lname):
self.first_name = fname
self.last_name = lname
def print_name(self):
print(self.first_name, self.last_name)
class child2(Person2):
def __init__(self, fname, lname):
super().__init__(fname, lname)
x = child2("小灰灰", "灰太狼")
x.print_name()
class person3:
def __init__(self, fname, lname):
self.first_name = fname
self.last_name = lname
def print_name(self):
print(self.first_name, self.last_name)
class child3(Person):
def __init__(self, fname, lname):
super().__init__(fname, lname)
self.year = 2021
x = child3("小红红", "红太郎")
print(x.year)
class Person4:
def __init__(self, fname, lname):
self.first_name = fname
self.last_name = lname
def print_name(self):
print(self.first_name, self.last_name)
class child4(Person):
def __init__(self, fname, lname, year):
super().__init__(fname, lname)
self.year = year
x = child4("小羊羊", "喜羊羊", 1998)
print(x.year)
class Person5:
def __init__(self, fname, lname):
self.firstname = fname
self.lastname = lname
def print_name(self):
print(self.firstname, self.lastname)
class child5(Person):
def __init__(self, fname, lname, year):
super().__init__(fname, lname)
self.year = year
def welcome(self):
print("Welcome", self.first_name, self.last_name, "to the class of", self.year)
x = child5("小羊羊", "美羊羊", 2021)
x.welcome()
|