i want to know why the output does not change my namef to "yolo" , and why it returns nonex2 when i remove the # from the first print statement
class Class():
def __init__(self,namef,namel):
self.name1=namef
self.name2=namel
self.email=print(f"{self.name1}{self.name2}@google.com")
def introself(self):
return(f"Hello guys my name is {self.name1}{self.name2} and i am a human")
human1=Class("chandra", "Shekar")
# print (human1.email)
human1.name1="yolo"
print (human1.email)
>Solution :
By setting human1.name1="yolo" you have updated an attribute of the instance "human1" of the class "Class". Now if you print human1.name1 it’ll be "yolo" as expected. namef is a parameter, not a variable, not a value, so I don’t see how you could even see that it isn’t changed as it never existed. As for human1.email, you’ve set it as print("a string"), print is a built-in function, calling print like this prints the string, but returns none, and then you printed none, so it shows none.