This is the code where I make two classes. In first I create email by arguments, in Second I create email by attributes. when I change the attributes manually they both show the same result of not updating the email? What am I missing here?
class Nam:
def __init__(self, first, last):
self.first = first
self.last = last
self.email = first + "." + last + "@gmail.com"
e = Nam("Ridhi","Shah")
print(e.first)
e.email
Ridhi
Ridhi.Shah@gmail.com
e.first = "Neha"
print(e.first)
e.email
Neha
Ridhi.Shah@gmail.com
Second Class
class Nam2:
def __init__(self, first, last):
self.first = first
self.last = last
# This is the line different from first class
self.email = self.first + "." + self.last + "@gmail.com"
e2 = Nam2("Nidhi","Shah")
print(e2.first)
e2.email
Nidhi
Nidhi.Shah@gmail.com
e2.first = "Sneha"
print(e2.first)
e2.email
Sneha
Nidhi.Shah@gmail.com
This class is still giving Nidhi. even after I used self.