class - python - setting instance variable within the instance -
i have following tile class got instance variables such unmapped,free etc. instance variables default value once new instance created, want set of variables method within instance itself. when im trying so, seems the new value not saved when im doing without method seems work. how can be?
class tile(): def __init__(self): self.free = 0 self.unmapped = 1 def set_tile(self,newval): self.free = newval
so : tile1 = tile() tile1.set_tile(20) -> tile1.free = 0 but, tile1.free = 20 -> tile1.free = 20
thanks help
Comments
Post a Comment