class Driver: def __init__(self,carType='default',driver='Tom'): self.carType=carType self.driver=driver def toString(self): return ' '.join([self.driver,'drive',self.carType]) def creatCarFactory(carType): def setCarDriver(carDriver): return Driver(carType,carDriver) return setCarDriverif __name__=="__main__": bus = creatCarFactory('bus') xalDriveBus = bus('xal') timDriveBus = bus('Tim') car = creatCarFactory('car') xalDriveCar = car('xal') print(xalDriveBus.toString())