Untitled

mail@pastecode.io avatar
unknown
python
a year ago
519 B
2
Indexable
Never
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)