Python实操使用类进行面试对象的编程

# shuang
# 开发时间:2023/8/21 21:07

class car():
    def __init__(self, type, no):
        self.type = type
        self.no = no

    def start(self):
        pass

    def stop(self):
        pass


class Taxi(car):
    def __init__(self, type, no, company):
        super().__init__(type, no)
        self.company = company

    def start(self):
        print(f'你好,我是{self.company}公司,车牌{self.no},你要去哪')

    def stop(self):
        print('到了,付钱下车')


class mycar(car):
    def __init__(self, type, no, name):
        super().__init__(type, no)
        self.name = name

    def stop(self):
        print('到了,我们去玩吧')

    def start(self):
        print(f'{self.name},我的车我做主,车牌{self.no},类型{self.type}')





if __name__ == '__main__':
    # play(mycar('GTZ','8888','本田'))
    #   mycar('GTZ','8888','本田')
    taxi=Taxi('GTZ','8888','石沉大海')
    taxi.start()
    taxi.stop()

    print('------'*10)
    my_car=mycar('GTZ','8888','我的')
    my_car.start()
    my_car.stop()

你可能感兴趣的:(Python,python,开发语言)