确保您已导入该time模块。在__init__()类的函数中,将 的值time.time()放入变量中,例如self.spawned_time.在你的类中创建一个名为can_destroy(). 该函数的代码如下:return time.time() >= self.spawned_time + <INSERT TIME THE CLASS WILL BE ALIVE>完整代码:import timeclass MyClass: def __init__(self): self.spawned_time = time.time() def can_destroy(self): return time.time() > self.spawned_time + 6 # replace '6' with the seconds the class will exist formy_instance = MyClass()while True: if my_instance.can_destroy(): # destroy your instance here