Untitled
unknown
python
2 years ago
519 B
5
Indexable
class Contact: def __init__(self, name,phone): self.name=name self.phone=phone def __dict__(self): return {"name":self.name,"phone":self.phone} def replace(self,old_value, new_value): classkeys=self.__dict__() for x,y in classkeys.items(): if y == old_value: # לא עובד # self+"."+key=new_value setattr(self, x, new_value) sun=Contact(name="sun",phone=12345) print(sun.__dict__()) print(sun.name) sun.replace("sun","ilay") print(sun.name)
Editor is loading...