May-31-2020, 12:46 PM
So I am learning classes in python and I stumbled across something that did not make sense to me.
In the code below, when I change the name of the student via calling the method changeName passing the new parameters (forename and surname), why doesn't it reflect the changes when I print the attribute fullname?
In the code below, when I change the name of the student via calling the method changeName passing the new parameters (forename and surname), why doesn't it reflect the changes when I print the attribute fullname?
class Student: def __init__(self, forename, surname): self.forename = forename self.surname = surname self.fullname = self.forename + " " + self.surname def changeName(self, forename, surname): self.forename = forename self.surname = surname s1 = student("billy", "smith") print(s1.fullname) s1.changename("tom", "jones") print(s1.fullname) ----> why is this not updating?