@classmethod # @classmethod 装饰器用于定义类方法 def_are_all_numeric(cls, input_list): for element in input_list: ifnotisinstance(element, (int, float)): returnFalse returnTrue
# 父类,动物 classAnimal: def__init__(self, name, age): self.name = name self.age = age defeat(self): print(f"{self.name} is eating.") defsleep(self): print(f"{self.name} is sleeping.")
# 子类,鸡 classChicken(Animal): def__init__(self, name, age, color): super().__init__(name, age) self.color = color deflay_egg(self): print(f"{self.name} is laying an egg.")