你可以使用__init__方法作为已经实例化的对象的setter

时间:2013-09-07 03:40:48

标签: python

从类创建实例对象后,您是否可以使用对象的 init 方法将其变量设置为新的?

前:

class Object1(Object):

    def __init__(self, name, ability):
        self.name = name
        self.ability = ability

example1 = Object1("example", "none")
#new object created with parameters set by the __init__ method 

example1.__init__("changeExample", "Changed")
#called the __init__ method on the object and changed the parameters.   Is this okay to do?

0 个答案:

没有答案