Changing variables in multiple Python instances

后端 未结 4 431
感情败类
感情败类 2021-01-18 22:24

Is there anyway to set the variables of all instances of a class at the same time? I\'ve got a simplified example below:

class Object():
   def __init__(self         


        
4条回答
  •  北海茫月
    2021-01-18 22:55

    What about using a class attribute?

    class Object():
        speed=0
    
    instance0=Object()
    instance1=Object()
    instance2=Object()
    
    Object.speed=5
    

提交回复
热议问题