Upon updating a value, the __init__ method still uses the old attribute value.
class Email:
def __init__(self, name):
self.name = name
self.email = self.name + "@hotmail.com"
def details(self):
return f'{self.name} | {self.email}'
person = Email("James")
print(person.details())
person.name = "Michael"
print(person.details())
Output gotten:
James | James@hotmail.com
Michael | James@hotmail.com
Output expected:
James | James@hotmail.com
Michael | Michael@hotmail.com
What am I doing wrong?
from Method attribute is not updating itself even though I'm clearly assigning a different value to it
No comments:
Post a Comment