def create_ball_class(): def init(self, color): self.color = color def getColor(self): return self.color return type( "Ball", (object,), { "__init__": init, "getColor": getColor, }, ) Ball = create_ball_class() ballObj = Ball("green") print(ballObj.getColor()) ...