0

got attribute error in last line. how?

class student: def __init__(self,name): self.name=name def sayhi(self): print("hi from"+ self.name) s1=student("amy") s1.sayhi()

20th May 2023, 2:39 AM
sudip pariyar
sudip pariyar - avatar
1 Answer
+ 5
Your definition of sayhi should not be made in the __init__() method try this: class student: def __init__(self, name): self.name = name def sayhi(self): print("hi from " + self.name) s1 = student("amy") s1.sayhi() I hope this helps :)
20th May 2023, 3:22 AM
Apollo-Roboto
Apollo-Roboto - avatar