class Dog():
def __init__(self, name, age):
self.name = name
self.age = age
def sit(self):
print(self.name.title() + " is now sitting.")
def roll_over(self):
print(self.name.title() + " rolled over!")
my_dog = Dog('whie', 6)
my_dog.sit()
my_dog.roll_over()
class Car():
def __init__(self, make, model, year):
"""初始化汽车属性"""
self.make = make
self.model = model
self.year = year
def get_descriptive_name(self):
"""返回整洁的描述性信息"""
long_name = str(self.year) + ' ' + self.make + ' ' + self.model
return long_name.title()
my_new_car = Car('audi', 'a4', '2016')
print(my_new_car.get_descriptive_name())
class ElectricCar(Car):
'''电动汽车'''
def __init__(self, make, model, year):
'''初始化父类的属性'''
super().__init__(make, model, year)
my_tesla = ElectricCar('tesla', 'model s', 2016)
print(my_tesla.get_descriptive_name())
class Restaurant():
def __init__(self, restaurant_name, cuisine_type):
self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type
def describe_restaurant(self):
print(self.restaurant_name + ' ' + self.cuisine_type)
def open_restaurant(self):
print("正在营业")
print("\n")
restaurant = Restaurant('面条店','烹煮')
restaurant.describe_restaurant()
restaurant.open_restaurant()
class IceCreamStand(Restaurant):
def __init__(self, restaurant_name, cuisine_type):
super().__init__(restaurant_name, cuisine_type)
self.flavors = []
def show_flavors(self):
for flavor in self.flavors:
print(flavor)
print("\n")
icecreamstand = IceCreamStand('冰激凌店', '冷冻食品')
icecreamstand.describe_restaurant()
print("冰激凌口味如下所示:")
icecreamstand.flavors = ['草莓', '芒果', '西瓜']
icecreamstand.show_flavors()
class cat:
def __del__(self):
print("hahaha")
a = cat()
b = a
print("="*20)
class Base:
def test(self):
print("---Base---")
class A(Base):
pass
class B(Base):
def test(self):
print("---B---")
class C(A, B):
pass
c = C()
c.test()
print(C.__mro__)